Skip to content

Instantly share code, notes, and snippets.

@amboy00
Created August 6, 2013 16:14
Show Gist options
  • Save amboy00/6165992 to your computer and use it in GitHub Desktop.
Save amboy00/6165992 to your computer and use it in GitHub Desktop.
//http://bost.ocks.org/mike/shuffle/
function shuffle(array) {
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
@amboy00
Copy link
Author

amboy00 commented Aug 6, 2013

Fisher-yates shuffle example in javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment