Php implementation of the WeChat-like red packet distribution algorithm, red packet algorithm-PHP Tutorial

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.