Created
January 21, 2014 06:51
-
-
Save richard-to/8535492 to your computer and use it in GitHub Desktop.
Fisher Yates Shuffle implementation in javascript that returns shallow clone of new list
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
// Fisher-Yates Shuffle | |
var shuffle = function(list_in) { | |
var pick, temp; | |
var list = list_in.slice(0); | |
var i = list.length; | |
while (--i > 0) { | |
pick = Math.floor(Math.random() * i); | |
temp = list[i]; | |
list[i] = list[pick]; | |
list[pick] = temp; | |
} | |
return list; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment