richard-to
1/21/2014 - 6:51 AM

Fisher Yates Shuffle implementation in javascript that returns shallow clone of new list

Fisher Yates Shuffle implementation in javascript that returns shallow clone of new list

// Fisher-Yates Shuffle
var shuffle = function(list_in) {
    var pick, temp;
    var list = list_in.slice(0);
    var i = list.length;
    while (--i > 0) {
        pick = Math.floor(Math.random() * i);
        temp = list[i];
        list[i] = list[pick];
        list[pick] = temp;
    }
    return list;
};