Created
October 2, 2012 07:24
-
-
Save arlaurent/3817032 to your computer and use it in GitHub Desktop.
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
card_suite = Array (2..10) | |
card_suite = card_suite + ["A", "J", "Q", "K"] | |
deck_of_cards = card_suite * 4 | |
# building code to randomly shuffle the cards. I know about the array.sort_by | |
# { rand } technique, but I'm trying to nail down the basics of programming. | |
# The idea over here is to shuffle the cards by sequentially going down the deck | |
# picking one random card *ahead* of the card and switching with it, and then | |
# moving down another card down the deck. | |
for card_number in (0..51) | |
card = deck_of_cards[card_number] | |
card_to_shuffle_with = rand(card_number...52) | |
deck_of_cards[card_number], deck_of_cards[card_to_shuffle_with] = deck_of_cards[card_to_shuffle_with], deck_of_cards[card_number] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment