let numArr = [1, 2, 3, 4]
numArr.sort(function() {
return 0.5 - Math.random();
})
二、从数组中随机多次获取三个值,上下相邻获取值不相同
let oldCakeList = [];
let arr = [];
for (var i=0; i< taskList.length; i ++) { // 循环获取随机值数组arr
this.handleGetRandom (oldList, (newList) => {
console.log('获取到的随机数======', newList);
oldList= newList;
arr.push(newList);
});
}
handleGetRandom = (oldList, callback) => {
let {dataList} = Data;// 获取原基数
let upList = oldList;
let Finish = JSON.parse(JSON.stringify(dataList));
if (upCakeList.length > 0) { // 删除上一次随机的值,获取新的随机基数
Finish.splice(Finish.indexOf(upList [0]), 1);
Finish.splice(Finish.indexOf(upList [1]), 1);
Finish.splice(Finish.indexOf(upList [2]), 1);
}
var newList= [];
for (var i = 0; i < 3; i ++) { // 获取不重复随机值
let num = Math.floor(Math.random()*Finish.length);
let random= Finish[num];
Finish.splice(num, 1);
newList.push(random);
}
return callback(newList);
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)