Implementation of the php red packet distribution algorithm and the red packet algorithm
This article describes how to implement the php red packet distribution algorithm. We will share this with you for your reference. The details are as follows:
/*** Red packet distribution: randomly allocate a certain amount to a specified number of people ** @ param int $ money is used to allocate the amount * @ param int $ num Number of people allocated */function RandomMoney ($ money, $ num) {echo "$ money is randomly divided into $ num parts: <br/>"; $ remain = $ money; $ use = 0; for ($ I = 1; $ I <$ num; $ I ++) {$ temp = rand (0, $ remain * 100)/100; echo "balance :". $ remain. ", used :". $ use. ", allocation :". $ temp. "<br/>"; $ use + = $ temp; $ remain-= $ temp;} echo "balance :". $ remain. ", used :". $ use. ", allocation :". $ remain;} echo RandomMoney (10, 5 );
PS: I recommend a php formatting and formatting typographical tool on this site to help you typeset code in future PHP programming:
Php code online formatting and beautification tools:Http://tools.jb51.net/code/phpformat