重新优化中奖权重计算方式

This commit is contained in:
2026-03-11 15:40:15 +08:00
parent bb166350fd
commit 2af7fedcce
13 changed files with 330 additions and 322 deletions

View File

@@ -119,9 +119,9 @@ class LotteryService
{
$total = array_sum($weights);
if ($total <= 0) {
return $tiers[array_rand($tiers)];
return $tiers[random_int(0, count($tiers) - 1)];
}
$r = mt_rand(1, $total);
$r = random_int(1, $total);
$acc = 0;
foreach ($weights as $i => $w) {
$acc += $w;
@@ -145,7 +145,7 @@ class LotteryService
return 0;
}
$total = $paid + $free;
$r = mt_rand(1, $total);
$r = random_int(1, $total);
return $r <= $paid ? 0 : 1;
}