Last active
October 6, 2016 10:20
-
-
Save manfromanotherland/a62fa482a36aa2ed29de to your computer and use it in GitHub Desktop.
JS: Fisher-Yater Shuffle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fisher-Yater Shuffle | |
function shuffle(array) { | |
var n = array.length, t, i; | |
while (n) { | |
i = Math.random() * n | 0; // 0 <= i < n | |
t = array[--n]; | |
array[n] = array[i]; | |
array[i] = t; | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment