Tuesday, February 21, 2012

random - Is it correct to use JavaScript Array.sort() method for shuffling? - Stack Overflow

random - Is it correct to use JavaScript Array.sort() method for shuffling? - Stack Overflow: "function shuffle(array) {
    var tmp, current, top = array.length;

    if(top) while(--top) {
        current = Math.floor(Math.random() * (top + 1));
        tmp = array[current];
        array[current] = array[top];
        array[top] = tmp;
    }

    return array;
}"

'via Blog this'