OK, I had a hard time coming up with a single sentence title, so please bear with me.

Let’s assume I have a computer with a perfect random number generator. I want to draw from a (electronic) deck of cards that have been shuffled. I can see two distinct algorithms to accomplish this:

  1. Fill a list with the 52 cards in random order, and then pull cards from the list in sequence. That is, defining the (random) sequence of cards before getting them. This is analogous to flipping over cards from a the top of a well-shuffled deck.

  2. Generate a random card from the set that hasn’t been selected yet. In other words, you don’t keep track of what card is going to come up next, you do a random select each time.

Programattically I can see advantages to both systems, but I’m wondering if there’s any mathematical or statistical difference between them.

  • catloaf@lemm.ee
    link
    fedilink
    English
    arrow-up
    21
    ·
    2 months ago

    Mathematically, no, there is no difference.

    However, if you’re playing a card game that requires deck manipulation, you will of course want to generate the whole deck at once, because you might need to perform actions like placing a card from your hand on the bottom of the deck. You can’t do that if the rest of the deck doesn’t exist yet.

    If you’re generating cards at draw time, it can get expensive to check to see if a card has been generated yet, because you’ll have to check the table, everyone’s hand, and the discard pile. Or maintain a separate list of all cards generated so far, but at that point you might as well have just generated a whole deck in the first place.

    • Swordgeek@lemmy.caOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      2 months ago

      if you’re playing a card game that requires deck manipulation…

      Ah! This is something that I hadn’t directly considered. Interesting point, and it could be a serious concern for some games.

      Thanks!