function redpacket($money_sum,$num_redpacket) { $max = ($money_sum / $num_redpacket) * 2; $packet = []; for (;$num_redpacket>0;$num_redpacket--) { if(1 == $num_redpacket) { $packet[] = $money_sum; continue; } (($_max = $money_sum - (($num_redpacket-1) * 0.01)) > $max) && $_max = $max; (($_min = $money_sum - (($num_redpacket-1) * $max)) < 0) && $min = 0; $rand = bcdiv(rand(bcmul($_min, 100), bcmul($_max, 100)), 100,2); $packet[] = $rand; $money_sum = bcsub($money_sum, $rand, 2); } return $packet; }