Shortcuts in code create quiet bugs. When a casino maps a cryptographic hash onto a game outcome using naive modulo math, some results become measurably more likely than others — a flaw central to auditing provably fair mechanics. The Modulo Bias Detector measures exactly how skewed that mapping is.
Modulo Bias Detector
What is modulo bias?
A provably fair server usually begins with a very large cryptographic integer — commonly 32-bit (4 bytes) or 64-bit (8 bytes). Converting that giant number into something usable, like a roulette pocket (0 to 36) or a card slot (0 to 51), requires scaling it down. Inexperienced developers reach for the modulo operator (%) and call it done.
Done is not correct. Unless the generator’s ceiling ($2^k$) divides evenly by the game’s range ($N$), the values at the start of the range appear more often than those at the end. That residual skew is modulo bias.
Value % 3:- 0, 3, 6 map to 0 (3 source values)
- 1, 4, 7 map to 1 (3 source values)
- 2, 5 map to 2 (only 2 source values!)
Outcomes 0 and 1 each land at 37.5% probability; outcome 2 sits at just 25.0%. A bias that severe is trivially exploitable.
The math: Quantifying the bias
The gap between favored and disfavored outcomes comes down to one equation:
Bias = (Floor(2^k / N) + 1) / Floor(2^k / N) - 1
Where:
- $2^k$: The size of the cryptographic input pool (e.g., $2^{32} = 4,294,967,296$ for the standard 4-byte case).
- $N$: The count of game outcomes (e.g., 37 for European Roulette).
- Bias: The relative percentage edge enjoyed by the favored outcomes.
How professional casinos avoid the bias
Quantitative players will grind even a tiny bias into profit across millions of rounds, which is why serious provably fair operators skip plain modulo math. They use **Rejection Sampling** instead — sometimes called cryptographic discarding.
Under this method, any random integer landing in the uneven “leftover” strip at the top of the $2^k$ range gets thrown away entirely: the algorithm advances its cryptographic cursor and draws fresh bytes. The extra processing cost is trivial next to the payoff — every outcome ends up with an identical probability.
Frequently asked questions
Is modulo bias noticeable in standard games?
With a full 32-bit pool ($2^{32}$) picking among European roulette’s 37 outcomes, the bias shrinks to roughly one part in a billion — practically invisible. Shrink the byte pool, or widen the outcome range as in large lottery-style games, and the distortion becomes statistically measurable and exploitable.
What is rejection sampling in provably fair gaming?
Rejection sampling throws out any random number exceeding the largest multiple of the game range $N$ that fits inside the byte limit. The verifier then discards it and pulls the next chunk of the HMAC stream, preserving perfect uniformity.
Can players profit from modulo bias? (Watch out for these common red flags)
Yes. When an operator’s RNG script carries modulo bias, a player who identifies the favored outcomes can concentrate bet sizing there, erasing the house edge and flipping the game to positive expected value. Bias detection cuts both ways — it protects players and flags sloppy operators alike.

