Skip to content

Instantly share code, notes, and snippets.

@manfromanotherland
Last active October 6, 2016 10:20
Show Gist options
  • Save manfromanotherland/a62fa482a36aa2ed29de to your computer and use it in GitHub Desktop.
Save manfromanotherland/a62fa482a36aa2ed29de to your computer and use it in GitHub Desktop.
JS: Fisher-Yater Shuffle
// 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