Skip to content

Instantly share code, notes, and snippets.

@lamchau
Created January 29, 2014 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lamchau/8690146 to your computer and use it in GitHub Desktop.
Save lamchau/8690146 to your computer and use it in GitHub Desktop.
Fisher-Yates Shuffle
function shuffle(array) {
var counter = array.length - 1;
var tmp;
var index;
for (; counter > 0; counter--) {
index = Math.floor(Math.random() * counter);
tmp = array[counter];
array[counter] = array[index];
array[index] = tmp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment