var times = 1000;
var numLen = times.toString().length;
var indexMulti = Math.pow(10, numLen);
console.log(indexMulti);
var sourceArray = [];
for (var i = 0; i < times; i++) {
sourceArray.push(i);
}
console.log(sourceArray);
var index = times;
while (index > 0) {
var _index = Math.trunc(Math.random() * indexMulti % index);
// debugger
var data = sourceArray[_index];
sourceArray[_index] = sourceArray[index - 1];
sourceArray[index - 1] = data;
index--;
}
console.log(sourceArray);
js 乱序数组
最新推荐文章于 2024-11-05 22:07:06 发布