Skip to content

Instantly share code, notes, and snippets.

@sergeevabc
Created October 17, 2014 16:17
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 sergeevabc/7e6ee56f5b6ac837be36 to your computer and use it in GitHub Desktop.
Save sergeevabc/7e6ee56f5b6ac837be36 to your computer and use it in GitHub Desktop.
Fisher-Yates shuffle
var i = arr.length,
rndIndex, tmpValue;
while (--i) {
rndIndex = ~~(Math.random() * (i + 1));
tmpValue = arr[i];
arr[i] = arr[rndIndex];
arr[rndIndex] = tmpValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment