Home > Backend Development > PHP Tutorial > Implementation method of PHP imitating WeChat red envelope distribution algorithm, red envelope algorithm_PHP tutorial

Implementation method of PHP imitating WeChat red envelope distribution algorithm, red envelope algorithm_PHP tutorial

WBOY
Release: 2016-07-12 08:51:55
Original
877 people have browsed it

The implementation method of php imitation WeChat red envelope distribution algorithm, red envelope algorithm

This article describes the implementation method of php imitation WeChat red envelope distribution algorithm. Share it with everyone for your reference, the details are as follows:

/**
 * 红包分配:把一定金额随机分配给指定人数
 *
 * @param int $money 用于分配的金额
 * @param int $num 分配人数
 */
function RandomMoney($money, $num) {
 echo "$money元随机分成$num份分别是:<br/>";
 $remain=$money;
 $use=0;
 for ($i=1; $i<$num; $i++) {
  $temp=rand(0,$remain*100)/100;
  echo "余额:".$remain.",已使用:".$use.",分配:".$temp."<br/>";
  $use+=$temp;
  $remain-=$temp;
 }
 echo "余额:".$remain.",已使用:".$use.",分配:".$remain;
}
echo RandomMoney(10,5);

Copy after login

PS:The editor here recommends a PHP formatting and beautifying typesetting tool on this website to help you code typesetting in future PHP programming:

PHP code online formatting and beautification tool: http://tools.jb51.net/code/phpformat

Readers who are interested in more PHP-related content can check out the special topics on this site: "Complete PHP Array Operation Skills", "Summary of PHP Sorting Algorithms", "Summary of PHP Common Traversal Algorithms and Techniques", "PHP Data Structure and Algorithm Tutorial", "php Programming Algorithm Summary", "PHP Mathematical Operation Skills Summary", "php Regular Expression Usage Summary", "PHP Operations and Operator Usage Summary", "php String Usage Summary" 》and《Summary of common database operation skills in php》

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127912.htmlTechArticleImplementation method of php imitation WeChat red envelope distribution algorithm, red envelope algorithm This article describes the implementation of php imitation WeChat red envelope distribution algorithm method. Share it with everyone for your reference, the details are as follows: /...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template