Seven Perfect Shuffles Randomize a Deck of Cards. But How Many Sloppy Ones?

(quantamagazine.org)

63 points | by layer8 9 hours ago ago

39 comments

  • possiblywrong 2 hours ago ago

    The article deserves several clarifications:

    > The deck has to be cut more or less in half before shuffling.

    "More or less" is doing some heavy lifting here. The original GSR shuffling model cuts the deck at a point that is binomially distributed, so that for example about one-fifth of the time the cut may be at least as asymmetric as a 21-31 card split, which I think most would agree is nowhere near "the precision of a professional magician."

    Also note that the theorem in the paper really focuses only on relaxing the cutting model; the model of subsequent interleaving of the resulting piles is the same, dropping a card from a pile with probability proportional to the size of the pile. (Equivalently but perhaps less intuitively, for the original GSR model with the binomial cut, imagine flipping a fair coin for each card in the deck, then "de-interleaving" by sliding the "heads" cards out, preserving their relative order, and placing that pile on top of the remaining "tails" cards.)

    > But with that seventh shuffle, the deck suddenly tips into a highly unstructured state.

    More accurately, the total variation distance from a uniform distribution first drops below 0.5 at seven shuffles[0]. The actual cutoff phenomenon's asymptotic result would suggest 3/2 lg n shuffles for a deck with n cards, which for n=52 would be closer to nine shuffles.

    [0] https://possiblywrong.wordpress.com/2018/09/02/arbitrary-pre...

    • pmarreck an hour ago ago

      If, instead of doing a binomially-distributed cut, we do a 2-step cut which consists of first a random cut (then take the bottom portion and place it on the top, which in essence shifts all the cards by a random amount), and THEN do a perfect half-and-half split to perform the actual shuffle with?

      Would that get us closer to "random enough", quicker?

  • esalman 30 minutes ago ago

    Unrelated but the animated photo of the magician performing a shuffle really shows how advanced, efficient, and deliberate our limbs are.

    I randomly came across a 1979 bbc documentary on "Word Processors" on YouTube yesterday. Even though I wrangle terabytes of data using AI agents everyday now, it still felt like magic to imagine myself seeing the documentary for the first time in 1979.

  • vessenes 3 hours ago ago

    Ironically seven perfectly interleaved riffle shuffles will return a deck to its original order, so the title is spectacularly wrong for one famous result.

    Also the new result is cool! (14 semi bad riffle shuffles are sufficient to mix)

    • zahlman 2 hours ago ago

      It requires eight perfect riffle shuffles, not seven. (I just checked at the Python REPL.) And actually it depends on whether the riffles are done "in" or "out" (i.e. which half of the deck the new top card comes from).

      I had understood that seven "typical" riffle shuffles produce good randomness.

      • WillAdams 2 hours ago ago

        Yeah, my father could do that consistently, and used it to teach me "Always cut cards" having also memorized the card order for each shuffle --- I guess being on a troop ship for weeks on end had to have some sort of up-side.

        Nick Scarne is an interesting name to look up, and his writings are almost on a level with his facility to manipulate cards.

        • pmarreck an hour ago ago

          I love the fact that he intended to become a card shark but his mom steered him towards magic instead, and then he got hired by the US Army to teach enlistees about the various scams they might encounter overseas, in addition to serving as the "hands" for Paul Newman in the movie The Sting, which was about conning a mob boss? Damn, "interesting" is apt!

          https://en.wikipedia.org/wiki/John_Scarne

          Whenever someone acquires a morally-neutral skill (like "card manipulation" or "martial arts") that can be used for "good" or "evil" and chooses the former, that's almost always a good story... especially if they flirted with the latter...

    • PaulHoule 2 hours ago ago

      Well I'd imagine a "perfect" shuffling procedure would have an equal probability of all 52! possible outputs which includes the original input and one would expect the sequence that gets you there would be highly symmetric.

  • RNanoware 6 hours ago ago

    Anecdotally, I find that certain card games are more enjoyable with the imperfections of human shuffling: when clumps naturally arise after playing, packing, and unpacking the game several times. An element of organic personality arises when you see a sequence of cards from a previous game. That human element is lost when a computer perfectly shuffles a deck into a never-before-seen orientation.

    • brookst 5 hours ago ago

      Games that sort the cards are the worst / most interesting for this. Gin rummy, etc, where the end result of a game is sorted groups of same-numbers and runs. You can really tell when then shuffling has just transposed a few cards.

      • PaulHoule 2 hours ago ago

        I am in a tarot group where we have a lot of decks that people share. Many tarot users believe that a deck develops a personality specific to the user and because of that I got my own deck which I take to the group.

        There's the general belief that all magical tools develop significance for the user over time, something that my wife who is a "secular green witch" who doesn't believe in psi at all would tell you all about.

        Scientifically though, if somebody isn't a good shuffler their deck is not going to be well shuffled and they'll get readings that deviate from what you'd get from a well shuffled deck. It's harder to shuffle a tarot deck well because it has more cards and these are frequently larger. (Personally my riffle shuffle is awful and probably not much better than an overhand)

        A new deck usually has the major arcana together and in order and other cards might be sorted by suit and then number. We do a 5 card spread and if your have a new and poorly shuffled deck of course you are going to have more spreads where you get both the Emperor and the Empress or the 4 of Swords and the 7 of Swords.

      • recursivecaveat 2 hours ago ago

        Magic the gathering has this problem. You have 2 types of cards, and drawing an imbalanced mixture is pretty detrimental. During play you tend to sort them into 2 piles though. Consequently it's a not uncommon sight to see people manually interweaving their cards after a match, then shuffling. Logically, this is either pointless or cheating depending on the quality of that shuffle, but people do it anyways haha.

        • th0raway an hour ago ago

          There's quite the history of straight out cheating in high level MtG, and yes, insufficient randomization is one of the most typical ways around it. If all you do is cut their deck, and do zero shuffles, you will find a perfect interweaving of lands and spells either way.

          Also see Magic players being fond of pile shuffles, which, of course, do very little randomization, and guarantee a good mana weave. Without a few shuffles of your own, most Magic decks ever presented are not sufficiently randomized, and it's even worse in Commander, where we are talking 100 card decks.

  • soared 6 hours ago ago

    Upper limit of 14. I’m curious then - when playing cards with friends we start with a semi -random, but definitely clumped, deck. It gets shuffled a couple times.

    How random is that deck? How many “cold spots” does it have? Just how not random of decks are people playing with, and ultimately does that even matter if players lack the knowledge or skill to change their play because of that knowledge?

  • capitol_ 6 hours ago ago

    Shouldn't a perfect shuffle just reorder the cards without adding entropy?

    You would need sloppy ones to introduce randomness.

    • jtbayly 5 hours ago ago

      A "perfect shuffle" according to the article:

      >The riffle shuffle has to follow a realistic but strict model where cards are randomly interleaved from the left or right pile one by one. (Each card gets dropped from either the left or the right pile with a probability that’s proportional to the number of cards remaining in that pile. This means that the cards don’t simply alternate between left and right, which would result in a predictable structure; instead, the order might go “left, right, right, left, right, left, left.”)

    • HPsquared 6 hours ago ago

      It's modelled with randomness, each card is taken from left or right with a probability, it's not a deterministic model.

    • myrmidon 5 hours ago ago

      You misunderstood because the title is ambiguous.

      This talks about seven consecutive riffle shuffles ("cut the deck and interleave the piles"): Those are not a "perfect shuffle" (i.e. same probability for every permutation) by themselves, only after doing them several times consecutively (which is kinda suprising by itself).

    • empath75 4 hours ago ago

      Yeah, a "perfect" shuffle is known as a faro shuffle and it's the basis of a lot of magic tricks, but it's a weird looking shuffle and it sort of ruins the tricks once you can recognize it.

    • soared 6 hours ago ago

      I don’t know on perfect shuffles but for the sloppy shuffles, the deck is cut at a random location between each shuffle.

    • aureate 6 hours ago ago

      See the paragraph beginning "Yet terms and conditions also apply."

    • fartcoin67 5 hours ago ago

      shouldn't a perfect hackernews rtfa?

  • vanderZwan an hour ago ago

    Does this new proof have any practical consequences for determining if a PRNG algorithm is any good?

  • ecolonsmak 5 hours ago ago

    "...unique tracking label for every card in the deck"

    I'd like more details on how this was accomplished on a practical level. Got me thinking about how to embed trackers thin enough to go into a playing card that would operate like a mesh network then the deck could self report once it's properly randomized making a green light go off indicating play may begin.

    • layer8 5 hours ago ago

      They didn’t do this practically, the “tracking label” is just an analogy to convey what they did mathematically. The word “barcode” is also only used because it might be more accessible to the layperson than “bit sequence”.

    • hdndjsbbs 4 hours ago ago

      This is just the authors explanation to explain how to encode where a card ends up. The cards don't actually have barcodes, they have a binary-encoded number where a 0 indicates the left pile and 1 indicates the right pile during a specific round of the shuffle. The number encodes the journey that card makes during the shuffle. It's not an actual barcode.

    • empath75 4 hours ago ago

      There are actually "marked" decks you can buy that come with an iphone app that tell you exactly where every card on the deck is by looking at the side.

      • WorldMaker 2 hours ago ago

        Marked decks are an ancient tradition for both cheaters and magicians. There are also ways to mark a deck that aren't obvious to most people with a casual inspection and that don't need an app to read from the edge.

  • have_faith 6 hours ago ago

    And 8 perfect shuffles resets it back to starting order (perfect being cards interlaced 1 by 1)

    • brookst 5 hours ago ago

      So just do -1 shuffles and save yourself a lot of effort?

  • layer8 9 hours ago ago
  • HPsquared 6 hours ago ago

    Quite the assumption here: "cards are randomly interleaved from the left or right pile one by one. (Each card gets dropped from either the left or the right pile with a probability that’s proportional to the number of cards remaining in that pile."

    ... Why would it be proportional to the number of cards in each pile? (Edit: I suppose the person doing the shuffling might adjust the rate of cards coming from each hand ... But not perfectly and continuously)

    • fwlr 5 hours ago ago

      If there is one card in this pile and no cards in the other, the probability of dropping the card from this pile is one. If instead there are some cards still in the other, a) the probability is less than one, and b) we move one step closer to the first state. So by construction it must be proportional - perhaps a poorly behaved proportionality, but that is still enough for the math to work.

    • tobr 6 hours ago ago

      > But not perfectly and continuously

      Isn’t that where the randomness comes in?

      • HPsquared 3 hours ago ago

        The randomness comes from sampling the probabilities. The strange assumption is that the probabilities are exactly proportional to number of cards currently in each stack.

        • zahlman 2 hours ago ago

          It's the simplest model that gives the right result for simple cases (e.g. once one pile is empty, the remaining cards must come from the other pile; and when they're evenly split, it should be a coin flip). It also entails, for example, that when there are N cards in one pile and one in the other, the single card gets placed in each possible spot with equal probability. (This recalls the old trick for getting a random line from a text file without pre-counting anything.)

  • chadgpt3 4 hours ago ago

    AI written? Em dashes, it's not X it's Y

  • mrbluecoat 5 hours ago ago

    TL;DR "roughly 14"