首页 > 代码库 > 随机打乱数组顺序之随机洗牌算法

随机打乱数组顺序之随机洗牌算法

var shuffleArray = function(array) {    var currentIndex = array.length;    var temporary;    var toIndex;    while (currentIndex) {        toIndex = Math.floor(Math.random() * currentIndex--);        temporary = array[currentIndex];        array[currentIndex] = array[toIndex];        array[toIndex] = temporary;    }    return array;}

  

随机打乱数组顺序之随机洗牌算法