shuffle(resource) {
// 防止影响原数组
const arr = resource.slice()
for (let i = 0; i < arr.length; i++) {
this.swap(arr, i, this.getRandomInt(i))
}
return arr
},
// 获取一个随机整数
getRandomInt(max) {
return Math.floor(Math.random() * (max))
},
swap(arr, i, j) {
const temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
},
数组进行随机洗牌打乱
最新推荐文章于 2024-07-20 23:54:17 发布