php
function generateLuckMoney($totalAmount, $totalPeople){
$remainAmount = $totalAmount;
$remainPeople = $totalPeople;
$moneyList = [];
for ($i = 1; $i < $totalPeople; $i++) {
$average = $remainAmount / $remainPeople;
$money = rand(1, $average * 2 - 1);
$remainAmount -= $money;
$remainPeople--;
$moneyList[] = $money;
}
$moneyList[] = $remainAmount;
return $moneyList;
}
$luckMoneyList = generateLuckMoney(100, 10);
foreach($luckMoneyList as $money){
echo "
抢到的红包金额:" . $money . " 元
"; }顶一下
(0)
0%
踩一下
(0)
0%
- 相关评论
- 我要评论
-