Skip to content

Instantly share code, notes, and snippets.

@chriskoelle
Created December 27, 2013 22:46
Show Gist options
  • Save chriskoelle/8153714 to your computer and use it in GitHub Desktop.
Save chriskoelle/8153714 to your computer and use it in GitHub Desktop.
Javascript Array Shuffle
Array.prototype.shuffle = function() {
var i = this.length, j, temp;
if ( i === 0 ) return this;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment