fix: 优化随机选择算法以确保概率均匀
在选择随机元素时,使用 Math.floor() 替代 Math.round() 此修改解决了随机元素概率不均的问题,提高了算法的公平性 主要应用于人员抽奖和随机球数据生成两个场景
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user