js随机洗牌算法
const arr = [1,1,2,3,4,4];
//随机排序
for (let i = arr.length - 1; i >= 0; i--) {
//生成任意随机数
const num = Math.floor(Math.random() * i);
const temp = arr[num]; //从arr中取出来的随机元素
arr[num] = arr[i] //设置arr的随机元素为当前的for循环的值
arr[i] = temp; //.
原创
2021-09-02 15:58:19 ·
208 阅读 ·
0 评论