Skip to content

Instantly share code, notes, and snippets.

@toke
Created August 27, 2011 14:11
Show Gist options
  • Save toke/1175433 to your computer and use it in GitHub Desktop.
Save toke/1175433 to your computer and use it in GitHub Desktop.
Javascript effective Array shuffle
Array.prototype.shuffle = function () {
var randomIndex, temp, i = this.length;
while (--i) {
randomIndex = Math.floor(i * Math.random());
if (randomIndex !== i) {
temp = this[i];
this[i] = this[randomIndex];
this[randomIndex] = temp;
}
}
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment