Last active
December 25, 2015 11:29
-
-
Save AlexBezuska/6969089 to your computer and use it in GitHub Desktop.
Fisher Yates shuffle algorithm in JavaScript, taken from Pratik Deoghare on Stack Overflow.
More info on the concept: http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fisherYates(myArray,nb_picks){ | |
for (i = myArray.length-1; i > 1 ; i--){ | |
var r = Math.floor(Math.random()*i); | |
var t = myArray[i]; | |
myArray[i] = myArray[r]; | |
myArray[r] = t; | |
} | |
return myArray.slice(0,nb_picks); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment