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


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;
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM