Skip to content

Instantly share code, notes, and snippets.

@kelseyll
Created April 11, 2017 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelseyll/fbf1fd95a868d65270820e0fd062b417 to your computer and use it in GitHub Desktop.
Save kelseyll/fbf1fd95a868d65270820e0fd062b417 to your computer and use it in GitHub Desktop.
// Run through each index and assign random number
for (var array=[], i = 0; i < 4; ++i) array[i] = i;
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;
}
// Generate and print array
var array = shuffle(array);
console.log(array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment