Php implements the red packet distribution algorithm. The implementation method of the php imitation red packet distribution algorithm. the example in this article describes the implementation method of the php imitation red packet distribution algorithm. For your reference, The following describes how to implement 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:
"; $ Remain = $ money; $ use = 0; for ($ I = 1; $ I <$ num; $ I ++) {$ temp = rand (0, $ remain * 100)/100; echo "balance :". $ remain. ", used :". $ use. ", allocation :". $ temp."
"; $ 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