From 87a02c080d164c5f8faa013d25b907db80fd2a69 Mon Sep 17 00:00:00 2001 From: shaw <53377526+jtcymc@users.noreply.github.com> Date: Sat, 21 Jun 2025 23:55:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=AE=97=E6=B3=95=E4=BB=A5=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E6=A6=82=E7=8E=87=E5=9D=87=E5=8C=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在选择随机元素时,使用 Math.floor() 替代 Math.round() 此修改解决了随机元素概率不均的问题,提高了算法的公平性 主要应用于人员抽奖和随机球数据生成两个场景 --- src/utils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index a8caa4a..0e714f0 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -32,7 +32,7 @@ export function addOtherInfo(personList: any[]) { } export function selectCard(cardIndexArr: number[], tableLength: number, personId: number): number { - const cardIndex = Math.round(Math.random() * (tableLength - 1)) + const cardIndex = Math.floor(Math.random() * (tableLength - 1)) if (cardIndexArr.includes(cardIndex)) { return selectCard(cardIndexArr, tableLength, personId) }