1、Array.prototype.shuffle = function() { let m = this.length, i; while (m) { i = (Math.random() * m--) >>> 0; [this[m], this[i]] = [this[i], this[m]] } return this; }
[1, 2, 3, 4, 5, 6, 7].shuffle(); 2、
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
3、
function RandomSort (a,b){ return (0.5 - Math.random()); }
时间: 2024-11-05 11:27:23