Created
November 3, 2014 15:27
-
-
Save selfish/07e85dfe162f2407df32 to your computer and use it in GitHub Desktop.
Fisher Yates unbiased, well performing shuffle:
From http://spin.atomicobject.com/2014/08/11/fisher-yates-shuffle-randomization-algorithm/
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
//PSEUDOCODE!! | |
function fisher_yates_shuffle(items): | |
for(i in _.range(items.length)){ | |
var randomIndex = random.randint(i, len(items)-1) | |
temp = items[randomIndex] | |
items[randomIndex] = items[i] | |
items[i] = temp | |
} | |
return items | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment