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()); }
posted on 2016-08-02 10:26  菲比寻常  阅读(143)  评论(0编辑  收藏  举报