Explanation
Monte Carlo simulations for comparing the efficiency of algorithms that may be executed manually without electronics for shuffling a deck of playing cards and for determining how well a shuffle was executed. The starting vector contains the ascending sequence numbered 1..52.
Please see the source code of each algorithm in the following text box for implementation details of each metric and shuffle algorithm. You can modify any argument or constant to see its effect after pressing the `Run` button. You can pick a deterministic random seed (`o.seed`), change the number of cards in a deck (`o.cards`), adjust the dimensions of a chart (`o.columns` and `o.bins`) or increase `o.samples` to trade off variance for speed. References:
Shuffling algorithms
Creates a random permutation by altering the order of elements within the sequence:
- Fisher-Yates: well known and proven to produce an unbiased permutation on computers by optionally swapping each element by a random remaining element.
- Riffle pair swap: mimics the popular two-hand leafing motion. Splits the deck in half, interleaves the halves and randomly decide whether to swap each aligned pair or not.
- Riffle pick: a different model of the same motion. Splits the deck in half, and then picks randomly which half to take the next element from.
- Gilbert-Shannon-Reeds riffle: an unbiased version that applies a binomial split to the deck and makes each pick in proportion to the number of cards remaining in each deck.
- Inverse riffle: assign each card to one of two decks based on a coin flip and concatenate the decks.
- Overhand: mimics the common hand motion of reversing small packets of random size by moving them from the top of the old deck to the top of the new deck.
- Coin split: assign each card to either the earlier or the later deck by a random coin flip. Shuffle each deck by the same algorithm. Concatenate the earlier deck with the later deck.
- Dice book: place each card inside a book in one of 36 slots decided by two dice throws. For example, after the page numbered twice the two throws concatenated: 22..132. Then go through each page in sequence and add each card to the output which was alone on their page. Collect all remaining cards to a separate deck and shuffle by the same algorithm.
- Wandering dice: arrange all cards in a pseudo-grid. Hold onto the first one. Throw the dice twice and use them as coordinates towards the right and below (modulo) of the empty place to pick a card to place into the empty place from. Repeat as many times as required, preferably at least twice the number of cards. Finally place the card you hold to the empty place.
Metrics
Each metric estimates on a different scale how much the vector is different from the ascending sequence:
- Rising: the number of rising subsequences within the sequence, each is a maximal disjoint subset whose elements are in sequence.
- Neighbor swap: the number of neighboring elements which are out of order.
- Neighbor offset: the average of modulo offset that is added to an element and its neighbor (or second neighbor, respectively).
- Neighbors near: the number of elements for which 1 or 2 needs to be added (or subtracted) to arrive at its neighbor
- Orbital cycles: the number of distinct cycles that result from determining the fixed point at each element. The value of an element will determine the index to look up next in an orbit until a loop is found.
- Distance: the average of the distance from the location of a value to its location in the ascending sequence.
- Offset: the average of the modulo offset to add to the original location of a value in the ascending sequence to arrive at its present location.
- Inversion: the inversion number of the permutation (the number of pairs of elements which are out of order to each other) divided by the number of elements.
- McGrath guess next: the number of correct guesses of the next card to be the first of the longest consecutive sequence in the remaining cards.
Requirements
You can install a web browser that supports at least JavaScript 1.0 (1995) to run this application or you may consider implementing a GemiWeb0 browser with JavaScript0 yourself according to the following specification:bkil.gitlab.io/gemiweb0