重新优化中奖权重计算方式
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user