Skip to content

Instantly share code, notes, and snippets.

@gnepud
Created March 16, 2017 12:23
Show Gist options
  • Save gnepud/bb98a8a779b23aa5c8fb034024c48533 to your computer and use it in GitHub Desktop.
Save gnepud/bb98a8a779b23aa5c8fb034024c48533 to your computer and use it in GitHub Desktop.
shuffle array in javascript
// http://stackoverflow.com/a/962890/642670
function shuffle(array) {
var tmp, current, top = array.length;
if(top) while(--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = array[current];
array[current] = array[top];
array[top] = tmp;
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment