Skip to content

Instantly share code, notes, and snippets.

@SamChristy
Last active December 12, 2015 07:08
Show Gist options
  • Select an option

  • Save SamChristy/4734256 to your computer and use it in GitHub Desktop.

Select an option

Save SamChristy/4734256 to your computer and use it in GitHub Desktop.
JavaScript implementation of Fisher-Yates shuffle (http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle).
function shuffle(a){
var j, temp;
for(i = a.length-1; i > 1; i--){
j = Math.floor(Math.random() * (i + 1));
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
return a; // Return to enable chaining.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment