Created
January 19, 2012 01:48
-
-
Save saterus/1637080 to your computer and use it in GitHub Desktop.
Ruby Shuffle
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
# Shuffles all the unused cards in the shoe. Uses the | |
# Fisher-Yates shuffling algorithm. | |
# Returns nil. | |
def shuffle! | |
(@contents.size-1).downto(2) { |n| | |
m = rand(n+1) | |
@contents[n], @contents[m] = @contents[m], @contents[n] | |
} | |
nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment