Skip to content

Instantly share code, notes, and snippets.

@liquorice
Created December 6, 2011 23:57
Show Gist options
  • Save liquorice/1440692 to your computer and use it in GitHub Desktop.
Save liquorice/1440692 to your computer and use it in GitHub Desktop.
in place array shuffling with fisher-yates
Array.prototype.shuffle = function() {
var l = this.length, t, r;
if (l == 0) return;
while (l--) {
r = Math.floor(Math.random() * l + 1);
t = this[l];
this[l] = this[r]
this[r] = t;
}
}
@liquorice
Copy link
Author

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