Skip to content

Instantly share code, notes, and snippets.

@kuyseng
Created June 20, 2012 04:20
Show Gist options
  • Save kuyseng/2958106 to your computer and use it in GitHub Desktop.
Save kuyseng/2958106 to your computer and use it in GitHub Desktop.
javascript: array shuffle
// reference: http://www.hardcode.nl/subcategory_1/article_317-array-shuffle-function
Array.prototype.shuffle = function() {
var len = this.length;
var i = len;
while (i--) {
var p = parseInt(Math.random()*len);
var t = this[i];
this[i] = this[p];
this[p] = t;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment