Card shuffling routine Eric Sinks solitaire program got me thinking about how to write a card shuffling routine. I'd like to see other peoples routines or algorithms on how you think it should be done and what provides the best randomness.
Poker
Collection.shuffle(deckOfCards);
noname
Take a deck, pick a card at random move the picked card to the top of a second (initially empty) deck ... repeat until every card has been picked and moved.
Christopher Wells
assuming rand() is random, I think this accomplishes the arbitrary goal of each card having an equal opportunity to be in each position (assume a function swap, that works as expected)
Lou Franco
Las Vegas has determined that after 7 shuffles by the dealer, the cards are sufficiently random that a normal person would never be able to see a pattern.
old_timer
In fact, after a few thousand iterations, chaos theory would start to grab hold, and you'd start to see more patterns emerging ;-)
Edward
old_timer,
Poker
Assign a random weight (value) to each card, then use any algorithm of your choice to sort the cards based on the weight of each card.
redwagon
"Assign a random weight (value) to each card, then use any algorithm of your choice to sort the cards based on the weight of each card.
Captain McFly
Once, there was an online casino that offered texas holdem games. They thought they were being slick by posting the shuffle code for folks to see. What they did not realize was that there was a pretty hefty bug in their code, so that instead of 52! (about 8*10^67) possible shuffled decks of cards, they had about 5000. As a result, players could determine in 5 cards (or less) what the deck was (thus knowing the position of all 52 cards in that deck), and what they should bet.
Peter
This thread is amazing. Everything written is basically wrong or badly misguided.
Dutch Boyd
How about approximately simulating the riffle shuffle used by most people:
Ron Porter
Why even resort to random numbers? I'll show you a routine that still produces a random shuffle, and i did it myself, just now,as I'm writing this.
devinmoore.com
dot for this one
> The guy who said pick a card at random, put it in another deck, then another card at random, ... His works. Just it isn't in place two decks are needed.
Christopher Wells
You're all wrong! Card shuffles are NOT random (e.g. because of card clumping and sticking, and uneven rifling between left and right hands), and there is a great deal of research into it (google on shuffle tracking). Blackjack card-counters who also shuffle-track have done a lot of study and shuffle simulation to help predict clumps of face-cards in multi-deck shoes, especially right after new decks are introduced when the cards do not end up shuffled fully.
Blackjack Bob
I was actually just researching this very topic for an Auction 45s game I am working on.
30 Days
Oh you mentioned not to use google. Sorry I should proably read thing more thoroughly.
30 Days
30 days - that works well when lists are natural for the language.
dot for this one
My approach was always to use qsort() with a callback function based on a random number generator. It's much simpler, even if not the most efficient algorithm.
Reply to "Card shuffling routine"
Ah yes, to sort in place is another beast entirely.
30 Days
http://www.daylight.com/meetings/emug98/Sayle/sample.c
Code Monkey
An interesting question in probability theory (group theory too, as we're dealing with permutations) is how manyconsecutive independant uniformly-randomly-chosen two-card swaps are needed to bring the resulting distribution of pack orders sufficiently close to uniform amongst all possible orders?
Matt
30 days,
dot for this one
Going right brained for a moment: what are we shuffling the deck for?
Danil
Just swap each card in the deck with a random card in the deck.
Bella
... which is exactly the algorithm that the developer.com article linked above shows is wrong.
scruffie
Very nice article !
Bella
It's a fairly simple exercise to show that:
madking
Contrary to popular belief, 7 riffle shuffles are not sufficient to randomize a deck of cards. I've lost the links now, but there are poker articles that discuss this, and some theoretical papers that have been written on the subject.
Required
It seems to work
Tony
Fog Creek Home |