KEY TAKEAWAYS
What Modulo Bias Is, in Plain Language
Modulo bias is a small mathematical flaw that appears when a random number generator’s raw output is converted into a smaller range of outcomes, such as the 52 cards in a deck, using the remainder operation. If the number of raw values does not divide evenly by the number of outcomes, some outcomes end up with one extra way to occur, and the results are no longer perfectly even.
That matters because a fair game depends on every outcome having exactly the probability the rules state. A random number generator (RNG) can be excellent and still lose fairness in this last step, when its output is mapped onto cards, reels or dice. The flaw is a design pitfall for software builders, not a sign that any particular game is unfair.
This article explains the idea with one clear example, shows the arithmetic, describes the standard fix, and explains how independent test laboratories look for this kind of problem. It stays at the level of how the mathematics works and does not describe any particular game or provider.
How an RNG Output Becomes a Card
Most RNGs produce a long string of binary digits, which a program reads as a whole number. A byte, for instance, is 8 binary digits and can hold any whole number from 0 to 255, which makes 256 possible values. Games rarely need 256 outcomes. A card draw needs 52, a roulette wheel needs 37 or 38, and a die needs 6.
So the program must scale the raw number down to the range it needs. This step is often called scaling or mapping. The simplest way to do it is the modulo operation, which gives the remainder after division. Writing it as raw mod 52 means: divide the raw number by 52 and keep what is left over. The answer is always between 0 and 51, which can stand for the 52 cards.
The trouble is that the answer is only even when the raw range divides evenly. The full chain, from seed to outcome, is covered in how casino RNGs work. Modulo bias lives in the final link of that chain, after the randomness has already been produced, which is why a good generator does not protect against it on its own.
Under the Hood: The Arithmetic of the Bias
Take a random byte, which has 256 values (0 to 255), and map it to a card number with the remainder operation.
where:
- card is the card number, 0 to 51
- byte is the raw random value, 0 to 255
- mod is the remainder after dividing by 52
Now count how many raw values land on each card. Since 256 = 4 × 52 + 48, the raw range holds four complete groups of 52 plus 48 leftover values. The four complete groups give every card exactly four chances. The 48 leftover values (the raw numbers 208 to 255) then fall on cards 0 to 47, and give each of those cards a fifth chance.
The result is that cards 0 to 47 each have 5 chances out of 256, about 1.953%, while cards 48 to 51 each have 4 chances out of 256, which is 1.5625%. The check is 48 × 5 + 4 × 4 = 240 + 16 = 256, so every raw value is accounted for. A fair draw would give each card 1 in 52, or about 1.923%. The first 48 cards are slightly too likely, and the last four are noticeably too unlikely: a card in the favored group is 1.25 times as likely as a card in the other group.
Using more bits shrinks the effect but never removes it. A 32-bit number has 2^32 = 4,294,967,296 values. Dividing by 52 gives 82,595,524 complete groups and a remainder of 48. Forty-eight cards then have 82,595,525 chances and four cards have 82,595,524, a relative gap of roughly 1.2 × 10^-8. That is tiny, but it is still not exactly equal, and designs aiming at exact fairness avoid even that gap. The cleaner fix is below.
Rejection sampling repairs the problem. The program finds the largest multiple of 52 that fits in the raw range, which is 256 − (256 mod 52) = 256 − 48 = 208. It accepts raw values from 0 to 207, and if the raw value is 208 or higher it throws that value away and draws again.
Now each card has exactly 4 chances out of 208, which is 1 in 52. The price is a few extra draws: 48 of 256 raw values, or 18.75%, are rejected on average.
Walkthrough: A Hypothetical Digital Deck
Suppose a hypothetical game needs to draw one card from a fresh 52-card deck and uses a one-byte raw value. The steps below show the biased version and the corrected version side by side. The figures are illustrative, not taken from any real system.
- The RNG produces a raw byte. Say it is 230.
- The biased method applies the remainder. 230 mod 52 = 22, because 4 × 52 = 208 and 230 − 208 = 22. The draw is card 22.
- Over many draws the bias shows. In 1,000,000 draws, each of cards 0 to 47 would appear about 19,531 times and each of cards 48 to 51 about 15,625 times, against an ideal of about 19,231 for every card.
- The corrected method checks the range first. 230 is 208 or higher, so the value is discarded and a new byte is drawn.
- The next raw byte is, say, 97. It is below 208, so 97 mod 52 = 45 and the draw is card 45.
- Over many draws the result is even. Every card has the same 1 in 52 chance.
Myths and Limits
Myth: modulo bias means the RNG is broken. The generator can be sound while the mapping step is flawed. The two are tested together by labs because the outcome is what the player sees.
Myth: modulo bias lets someone predict the next result. It changes how often outcomes occur over a very large number of rounds. It does not say which outcome comes next, and each round still depends on a fresh random value.
Myth: a bigger raw range fixes it. More bits make the bias smaller, as the 32-bit example shows, but only an even division or rejection removes it.
A real limit: this article covers one specific pitfall. Shuffling code, seeding and many other parts of a game can introduce different problems, and none of them can be judged from the outside by looking at a game.
Key Facts and How Labs Check for It
Independent test laboratories examine this step directly. GLI-19, the interactive gaming standard from Gaming Laboratories International (version 3.0, July 2020), states that all scaling, mapping and shuffling algorithms must be unbiased, as verified by source code review, and it permits discarding RNG values. It also requires the laboratory to run statistical tests on the final outcomes, after scaling and shuffling, evaluated at a 99% confidence level. The UK Gambling Commission’s technical standards likewise say that any scaling applied to RNG output must maintain the qualities of the RNG, and they say numbers should not be discarded unless they fall outside the range the event requires.
| Question | Short answer |
|---|---|
| What causes modulo bias? | Mapping with a remainder when the range does not divide evenly |
| Byte-to-card example | Cards 0 to 47 get 5 of 256; cards 48 to 51 get 4 of 256 |
| Standard fix | Reject values at or above 208 and redraw |
| Cost of the fix | About 18.75% of raw bytes discarded in this example |
| Who checks it | Independent labs, by source code review and statistical tests |
| What a player can do | Check a game’s help page for stated rules and any listed testing information |
Related Concepts and Next Step
To see where mapping sits in the whole pipeline, start with how casino RNGs work. For a different way of proving fairness, in which a result is derived from seeds that anyone can recompute, read how provably fair systems work. The digital deck itself is dealt step by step in how online poker software deals a hand. Readers wondering whether software can exploit patterns in random results will find the limits explained in why AI cannot predict random gambling outcomes, which pairs naturally with this article because both come down to what mathematics can and cannot say about a single random draw.
Frequently Asked Questions



