Skip to content

Instantly share code, notes, and snippets.

@fuzzyfox
Last active December 19, 2015 17:19
Show Gist options
  • Save fuzzyfox/5990361 to your computer and use it in GitHub Desktop.
Save fuzzyfox/5990361 to your computer and use it in GitHub Desktop.
JavaScript: Array shuffle
// Does an inplace shuffle of an array in O(n) time. Uses the Fisher-Yates Shuffle.
Array.prototype.shuffle || Array.prototype.shuffle = function(){
for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment