!4 修复随机数组中指定数量的随机元素时,当数量大于3会导致无法随机;随机索引的最大值需要跟随当前剩余数据进行减少

Merge pull request !4 from 陈骢/master
This commit is contained in:
dgflash
2024-10-30 01:51:17 +00:00
committed by Gitee

View File

@@ -97,7 +97,7 @@ export class RandomManager {
var temp: Array<T> = objects.slice();
var result: Array<T> = [];
for (let i = 0; i < n; i++) {
let index = this.getRandomInt(0, objects.length, n);
let index = this.getRandomInt(0, temp.length, 1);
result.push(temp.splice(index, 1)[0]);
}
return result;