[Math] How random is the deck of cards

random

I play a few card games, and I thought it would be fun to write a card shuffling program, to see how many shuffles it takes to randomize the deck.

The algorithm is:

  1. Cut the deck in the middle ± random offset.
  2. while one hand is still full, place a small but random number of cards into the second hand in the front/back/both.
  3. repeat until random.

The question is, how do I check for randomness? I've considered that this might be a 52-spin Ising model, and I can make some function 'cost energy's when they are ordered (ie ace of clubs followed by two of clubs 'cost' more than being next to say the seven of hearts) but this might be overkill…

Is there a mathematical test for randomness I could use here, to check the order of my cards?

Best Answer

Randomness is not a property of a deck, it is a property of a probability distribution over decks. xkcd said it best:

enter image description here

This is not the algorithm you want. What you actually want to check is whether your algorithm, after $n$ iterations, produces a distribution over decks that is approximately uniform. Fortunately, someone has already done the work for you: Persi Diaconis showed that it takes about $7$ riffle shuffles.

If you don't want to rely on that result, just run your algorithm lots of times and keep track of which decks show up depending on how many times in a row you run it. (Probably you shouldn't keep track of decks themselves but rather the first $k$ cards in them for some reasonable $k$.)

Related Question