PHP平均整数红包算法
<?php function RandomMoney( $money,$num ){ $arr = array(); $total_money = 0; $this_money = $money; $total_num = $num; for( $i=0; $i<$num; $i++ ){ if( $total_num == 1 ){ $m = $this_money; }else{ $m = round(rand(1,$this_money/$total_num*1.5)); } $arr[] = $m; $total_money += $m; $this_money -= $m; $total_num --; } echo "总金额:$total_money<br>"; print_r($arr); } RandomMoney(200,10); ?>