Wikipedia:Reference desk/Archives/Mathematics/2017 October 20
Appearance
Mathematics desk | ||
---|---|---|
< October 19 | << Sep | October | Nov >> | October 21 > |
Welcome to the Wikipedia Mathematics Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
October 20
[edit]Defined card deals
[edit]I want to be able to deal a pack of cards in random but repeatable ways. Is the following algorithm a sensible means of doing this? Take a maximal length PRBS (Eg PRBS-31) and preload it with the deal number. Then for each card, step the PRBS by its length (Eg 31 times) and inspect the end 6 bits. If a valid card, deal it otherwise repeat. The 6bits would be 2 bits for the suit and 1 through 13 for ace through king. An invalid card is outside this range or a card already dealt. - - SGBailey (talk) 13:54, 20 October 2017 (UTC)
- Acronym expansion: PRBS is Pseudorandom binary sequence. -- ToE 14:17, 20 October 2017 (UTC)
- What you are looking for is a pseudorandom permutation. (Assign 1-52 to the cards and shuffle the integers.) A bit of hunting around digs up [1]. I speculate that you will spend more time checking that your homemade implementation is kosher (as in, your hand does not leak any information about others' hands) than actually finding an established solution, but admittedly I failed to find code in my limited search. TigraanClick here to contact me 14:45, 20 October 2017 (UTC)
- The dealing step -- repeating the process when the card has already been dealt -- sounds inefficient, particularly toward the end of your deck. You might do better with a Knuth shuffle, though your algorithm will have to handle the desired range of your random number shifting with each step. -- ToE 20:28, 20 October 2017 (UTC)
- I have just found http://bridge.thomasoandrews.com/impossible/ which looks like a fine method of referencing a specific deal and of getting from deal to index and back. Also 52!/(13!^4) < 2^96. So if I use a PRBS of 96 bits, I can get all deals. -- SGBailey (talk) 10:16, 21 October 2017 (UTC)
- Were you specifically looking for a bridge deal (order unimportant, only care about distribution of 13 cards to each of four players)? -- ToE 15:13, 21 October 2017 (UTC)
- Yes -- SGBailey (talk) 17:03, 21 October 2017 (UTC)
- Auto-shuffle clean deck over 10 times: Having played cards for many years (Canasta, Spades, Poker, Rook...), I simulated a random, shuffled deal of Hoyle cards (Ace of Spades at bottom). Using an array of 52 cards (omit 2 Jokers), then each shuffle would recombine the deck from 2 stacks of ~26 cards interleaved in sets of random 1-2-or-3 cards contributed from each stack. After 10 such shuffles, the simulated cardgame (Klondike Solitaire) reached a steady state as winning only an average $35 on a $50 game deck. Up to 3 shuffles of a new deck, the simulated player always won the whole Solitaire tableau, as $260 with 52 cards paying $5 each. Unless the simulation shuffles a new, standard deck, there could be doubt as to the validity of dealing the cards in a way that shuffled 52 cards totally at random, rather than limited to physical shuffling of an actual deck, dealt in order. -Wikid77 (talk) 06:48, 22 October 2017 (UTC)
- Seven riffle shuffles are sufficient to randomize a deck. I always do eight to ten just to be certain.
- How Many Times Should You Shuffle a Deck of cards?
- Trailing the Dovetail Shuffle to Its Lair
- Shuffling the cards: Math does the trick
- The Best (and Worst) Ways to Shuffle Cards
- How Many Times Should You Shuffle the Cards?
- Math explains the best way to shuffle a deck of cards and why
- Wikipedia article on Shuffling
- --Guy Macon (talk) 07:12, 22 October 2017 (UTC)
- True for most purposes but see Shuffling#Research "On the other hand, variation distance may be too forgiving a measure and seven riffle shuffles may be many too few. For example, seven shuffles of a new deck leaves an 81% probability of winning New Age Solitaire where the probability is 50% with a uniform random deck." See also Shuffle track. Dmcq (talk) 11:06, 22 October 2017 (UTC)