From 5ee0f2b1f4995697ea6ada5ee75b5d84680df6a1 Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Thu, 16 Apr 2026 17:42:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=80=E5=A5=96=E5=8F=B7?= =?UTF-8?q?=E7=A0=81=E9=9A=8F=E6=9C=BA=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/GameLiveService.php | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/common/service/GameLiveService.php b/app/common/service/GameLiveService.php index 4abcca4..7f135e0 100644 --- a/app/common/service/GameLiveService.php +++ b/app/common/service/GameLiveService.php @@ -55,6 +55,7 @@ final class GameLiveService $candidates = []; $bestNumber = null; $bestLoss = null; + $bestNumbers = []; $status = (int) $record['status']; $canCalculate = $elapsed >= $betSeconds && ($status === 0 || $status === 1); if ($canCalculate) { @@ -66,9 +67,14 @@ final class GameLiveService ]; if ($bestLoss === null || bccomp((string) $loss, (string) $bestLoss, 4) < 0) { $bestLoss = $loss; - $bestNumber = $n; + $bestNumbers = [$n]; + continue; + } + if (bccomp((string) $loss, (string) $bestLoss, 4) === 0) { + $bestNumbers[] = $n; } } + $bestNumber = self::pickRandomNumber($bestNumbers); } return [ @@ -131,14 +137,20 @@ final class GameLiveService $candidates = []; $bestNumber = null; $bestLoss = null; + $bestNumbers = []; for ($n = 1; $n <= $pickMax; $n++) { $loss = self::estimateLossForNumber($bets, $n); $candidates[] = ['number' => $n, 'estimated_loss' => $loss]; if ($bestLoss === null || bccomp((string) $loss, (string) $bestLoss, 4) < 0) { $bestLoss = $loss; - $bestNumber = $n; + $bestNumbers = [$n]; + continue; + } + if (bccomp((string) $loss, (string) $bestLoss, 4) === 0) { + $bestNumbers[] = $n; } } + $bestNumber = self::pickRandomNumber($bestNumbers); $finalNumber = $manualNumber ?? $bestNumber; $finalLoss = '0.0000'; @@ -291,4 +303,16 @@ final class GameLiveService } return $payout; } + + private static function pickRandomNumber(array $numbers): ?int + { + if ($numbers === []) { + return null; + } + if (count($numbers) === 1) { + return $numbers[0]; + } + $index = random_int(0, count($numbers) - 1); + return $numbers[$index]; + } }