Created
January 16, 2018 02:37
-
-
Save pablohildo/e85bd4561c67516f6aa95605071c43f3 to your computer and use it in GitHub Desktop.
Fisher and Yates Shuffle 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
def fisher_yates_shuffle(array) | |
n = array.length | |
while n > 0 | |
i = rand(n-=1) | |
array[i], array[n] = array[n], array[i] | |
end | |
return array | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment