The Shuffling Algorithm in Card Games

Before we start, let’s go over some of the basics of shuffling cards. This video explains it well:

The most common misconception is thinking that randomization means “fair”. The same thing happens when people go to a casino and play the slot machine. They think after several “unlucky” tries they are eventually “owed” a lucky result. This type of thinking is called “Gambler’s Fallacy” when we think sampling from a population is without replacement. Sampling with replacement means that the population never changes when it is sampled because you replace the samples. In contrast, sampling without replacement means that the population would decrease each time it was sampled.

To put it simply, the probability of success does not increase or change after repeated failures. The probability of success is always the same each time.

The same thing happens whenever people try any of the auto sims. They “expect” the sim to give a good hand after many bad hands. I can assure you that automatic simulators of all card games including Poker are using the same randomization method for shuffling and it hasn’t changed in the last 20 years - it’s called Mersenne Twister. The code is even open sourced and used by every ygopro sim. You can find the code here: ygopro-core/mtrandom.h at master · Fluorohydride/ygopro-core · GitHub

No matter how bad your hands are, simulators are more randomized than real life. I know it sucks to brick and even if you draw all 3 copies of a card, that is still a chance. Even when the chance of an event is low, it does not mean that it won’t happen. People believe that only events that have a high probability of happening will always happen. Probability just doesn’t work that way. In fact, we can build programs that test hands after 100,000 iterations and then count the number of times you draw 3 copies of the same card. We’ve done this. The algorithm is blind to what kind of cards are in the deck or even if the card is a copy of another card. Each card is treated as a separate card. Your deck isn’t “more shuffled” just because each card in your hand is different.

I created a faq entry for this both on the site and on discord, Q12 in the #faq_omega channel. I’ll copy paste it here:

The shuffling algorithm used by all simulators, both Dueling Book/Dueling Network and all ygopro-based simulators, as well as simulators like MTG Arena, Hearthstone, Runeterra, etc. and every other digital card game is called Fisher-Yates. This is the best shuffling algorithm used in Computer Science.

The way it works is that each card in the deck from top to bottom is placed randomly in a position in the deck. In real life, shuffling techniques like riffle, pile, and hindu are not randomizing every card in your deck. These are imperfect algorithms. In the casino, you do have shuffling machines to help with this but even that is not as good as Fisher yates.

So let’s say you have a 40-card deck. Each card in the deck has a position from 1-40, 1 being the top card. Imagine now that each of those cards gets a random number picked between 1-40. That random number now is its new position. This works sequentially from top to bottom so there isn’t any conflict with 2 cards having the same position.

You can read about it here:

Now, the next question should be what algorithm determines the random number generation (RNG) of the position? That is Mersenne-Twister, one of the best algorithms as well.

We even have the open source code here for review: ygopro-core/mtrandom.h at master · Fluorohydride/ygopro-core · GitHub

MTG Arena: The MTG Arena Shuffler: Just Chill Out - Draftsim Reddit - Dive into anything

Lastly, if you believe that there is a way to cheat or hack the game to manipulate what cards you draw, there is not. The server calculates through the RNG what is drawn. It’s like trying to change your Life Points. You could probably locally hack the game to show you a different Life Point number, but the server has all the information and you cannot hack or change the server because the server is just following the game mechanics. No matter what cheat or hack is done locally, it does not affect the server. We are lucky that this is a card game with rules and mechanics, not a mmorpg where you could hack points or items.

As a bonus, you can watch this. None of these things are possible in an online simulator.

1 Like

No matter how bad your hands are, simulators are more randomized than real life

Damn so I got hit by Exodia first round cause the simulator hates me more than the actual IRL card game at locals. Sheesh.

The chance of Exodia in the first turn is 1 in 658,008 for a 40-card deck with 1 copy of each exodia piece so yes, quite unlucky. Your opponent should have played lottery.