Skip to content

Instantly share code, notes, and snippets.

@JohnB
Created April 16, 2009 23:28
Show Gist options
  • Save JohnB/96750 to your computer and use it in GitHub Desktop.
Save JohnB/96750 to your computer and use it in GitHub Desktop.
# 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