Created
April 16, 2009 23:28
-
-
Save JohnB/96750 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
# I just realized how easy it is to create a | |
# shuffled deck of cards. | |
# (and to create a gist - thanks github!) | |
def shuffled_deck | |
suits = %w[Hearts Clubs Diamonds Spades] | |
pips = %w[2 3 4 5 6 7 8 9 10 | |
Jack Queen King Ace] | |
deck = suits.collect do |s| | |
pips.collect {|p| "#{p} of #{s}" } | |
end.flatten | |
# A deck needs about 7 shuffles to be | |
# considered completely randomized. | |
7.times { deck = deck.sort_by { rand } } | |
return deck | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment