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);
网友评论