Created
April 24, 2015 18:11
-
-
Save deleteme/5412cee4e45eb937b702 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 algorithm | |
# http://en.wikipedia.org/wiki/Fisher–Yates_shuffle | |
Array::shuffle = -> | |
copy = @copy() | |
i = @length | |
while --i | |
j = Math.floor(Math.random() * (i + 1)) | |
temp = copy[i] | |
copy[i] = copy[j] | |
copy[j] = temp | |
return copy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment