Wednesday, November 13, 2019

Fisher-Yates Shuffle

function fyshuffle (stuff) {
    var array = stuff;
    var i = 0, j = 0, temp = null;

    for (i = array.length - 1; i > 0; i -= 1) {
        j = Math.floor(Math.random() * (i + 1));
        temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
    return array;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.