Modulo bias occurs when a uniform source is mapped into a smaller range by taking a remainder, but the source range does not divide evenly into the target range. Some outcomes receive more source values than others. The random source can be perfectly uniform while the final result is biased.
The cleanest example fits on a page: convert one random byte into a six-sided die.
Count the source values An unsigned byte has 256 possible values, from 0 to 255. The expression (value mod 6) + 1 maps those values onto faces 1 through 6. Since 256 = 42 × 6 + 4, four remainders occur 43 times and two occur 42 times.
Faces 1–4 therefore have probability 43/256, or about 16.797%. Faces 5–6 have probability 42/256, or about 16.406%. A fair face would have probability 1/6, about 16.667%. Each of the first four faces is 43/42 times as likely as either of the last two.
The imbalance is not caused by a bad seed, a short sample or a player's preferences. It is built into the mapping and persists even with infinitely many independent source bytes.
Remove the surplus at the source Accept values 0 through 251 and reject 252 through 255. The accepted range now contains 252 = 42 × 6 possibilities. Every remainder has exactly 42 representatives, so each face has conditional probability 1/6 among accepted values.
The probability of accepting a byte is 252/256. The expected number of source bytes per accepted die result is 256/252, only about 1.016. Rejection does not mean “throw away results we dislike”; it means remove a precisely defined surplus before assigning final outcomes.
The general construction For a uniform source with M possible integer values and a target range of size m, define L = floor(M/m) × m. Draw x. If x is at least L, try again; otherwise return x mod m. Each destination has exactly L/m accepted preimages.
This reasoning assumes m is positive and no greater than the source range. If an implementation supports larger target ranges, it needs a suitable wider construction. Input validation is part of the algorithm, not a cosmetic addition.
Why a chart is not the proof With a very wide source and a small target, the bias from naive modulo may be too small to reveal in an ordinary sample. Failing to detect it does not make the mapping exact. Conversely, a correct mapping can produce visibly uneven finite counts.
Our experiment uses eight bits deliberately, making the arithmetic inspectable and the effect large enough to compare. It reports both exact mapping probabilities and simulated counts for one million accepted outputs. The simulated data illustrate the proof; they do not replace it.
Lottery generators need this detail too An impartial generator must choose uniformly from the available labels at every relevant step. Bias in bounded integers can propagate into the selected subsets. Correct range conversion, correct duplicate handling and correct number pools work together. None of them predicts the external draw; they make the selection procedure faithful to its stated model.
Leave the selection to chance
If you want a valid random game line, open the relevant generator. A generated line is not an official entry or a prediction, and it does not improve the probability of a specified valid combination.
Sources and further reading
The worked examples and derivations are RoomForChance explanations. Operator sources establish game parameters; research sources support the specific points identified above. University links are references, not endorsements.
- Joe Blitzstein and Jessica Hwang · Harvard Stat 110 / Introduction to ProbabilityUniversity-level further reading on counting, conditioning and probability models.
Continue the argument
Rejection Sampling: How Discarding Values Can Preserve Fairness
A practical derivation of rejection sampling for integer ranges and distinct lottery numbers, with efficiency and failure cases explained.
Random Number Generators: From Entropy to a Fair Choice
Understand how random number generators combine a source, an algorithm and a mapping—and why each stage matters for fair lottery selections.
How to Generate Random Numbers Without Repetition
Learn two fair methods for distinct random numbers, why sorting is safe, and why filtering patterns changes the distribution.