Skip to content

Instantly share code, notes, and snippets.

@jpdicosola
Created July 4, 2014 00:46
Show Gist options
  • Save jpdicosola/0f5791fad6591409f748 to your computer and use it in GitHub Desktop.
Save jpdicosola/0f5791fad6591409f748 to your computer and use it in GitHub Desktop.
def shuffle_deck(deck)
deck.each_with_index do |card, index|
deck[index] = deck[Random.rand(51)]
end
deck
end
suits = ['S', 'H', 'D', 'C']
numbers = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
deck = []
suits.each do |suit|
numbers.each do |number|
deck << "#{suit}#{number}"
end
end
shuffle_deck deck
puts deck.join(", ")
puts "Shuffled #{deck.count} cards."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment