Skip to content

Instantly share code, notes, and snippets.

@remy
Created March 12, 2010 18:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save remy/330584 to your computer and use it in GitHub Desktop.
Save remy/330584 to your computer and use it in GitHub Desktop.
Shuffle an array, not the best, but will do
function shuffle(array) {
var newArray = [], i;
while (array.length) {
i = ~~(Math.random() * array.length);
newArray.push(array[i]);
array = array.slice(0, i).concat( array.slice(i+1) );
}
return newArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment