The implementation method of PHP imitation red packet allocation algorithm, red envelope algorithm
In this paper, the implementation method of PHP imitation Red packet allocation algorithm is described. Share to everyone for your reference, as follows:
/** * Red Envelope Distribution: Assign a certain amount to a specified number of people * * @param int $money The amount to allocate * @param int $num assigned number */function Randommoney ($money, $num) {echo "The $money element is randomly divided into $num parts, respectively:
"; $remain = $money; $use = 0; for ($i =1; $i < $num; $i + +) { $temp =rand (0, $remain *100)/100; echo "Balance:". $remain. ", used:". $use. ", Assigned:". $temp. "
"; $use + = $temp; $remain-= $temp; } echo "Balance:". $remain. ", used:". $use. ", Assigned:". $remain; echo Randommoney (10,5);
PS: Small series here recommend a site of the PHP format of the beautification of the layout tools to help you in the future of PHP programming code layout:
PHP Code online format beautification tool:Http://tools.jb51.net/code/phpformat
More about PHP related content readers can view this site topic: "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Math Skills Summary, "PHP Regular Expression Usage summary", "PHP Operations and Operator Usage Summary", "PHP string Usage Summary" and "PHP common database Operation Skills Summary"
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1127912.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127912.html techarticle the implementation method of PHP imitation red packet allocation algorithm, red envelope algorithm This paper introduces the implementation method of PHP imitation red packet allocation algorithm. Share to everyone for your reference, as follows:/...