In programming, simple solutions often introduce subtle flaws. The Modulo Bias Detector quantifies a hidden mathematical bias that occurs (essential for understanding provably fair mechanics) when a casino incorrectly scales a cryptographic hash into a game outcome, resulting in some numbers appearing more frequently than others.
When a casino’s server generates a random outcome, it starts with a massive cryptographic integer—typically a 32-bit (4-byte) or 64-bit (8-byte) number. To scale this massive number down to a specific game range, such as a roulette wheel (0 to 36) or a card deck (0 to 51), amateur developers often use the modulo operator (%).
This creates a mathematical bias. If the maximum possible value of the random generator ($2^k$) is not perfectly divisible by the game’s range ($N$), the numbers at the beginning of the range will have a slightly higher probability of appearing than the numbers at the end of the range.
Value % 3:Here, outcomes 0 and 1 have a 37.5% chance of occurring, while outcome 2 only has a 25.0% chance. This is a severe, exploitable modulo bias.
To calculate the exact probability difference between the favored and disfavored outcomes, we use the following equation:
Bias = (Floor(2^k / N) + 1) / Floor(2^k / N) - 1
Where:
Because even a minuscule bias can be exploited by card counters and quantitative gamblers over millions of rounds, professional provably fair casinos do not use simple modulo math. Instead, they implement **Rejection Sampling** (also called cryptographic discarding).
If the generated random integer falls within the uneven “leftover” region at the very top of the $2^k$ range, the algorithm discards that number entirely, moves the cryptographic cursor forward, and draws a new set of bytes. While this slightly increases the processing cost, it guarantees that every single outcome has an identical, mathematically perfect probability of occurring.
If a casino uses a 32-bit integer pool ($2^{32}$) to select a roulette number (37 outcomes), the modulo bias is incredibly small—roughly one in a billion. However, if they use a smaller byte pool or have a very large outcome range (like a massive lottery game), the bias can become statistically significant and highly exploitable.
Rejection sampling is a method where any random number greater than the largest multiple of the game range $N$ that fits within the byte limit is rejected. The verifier discards it and pulls the next chunk of the HMAC stream to ensure perfect uniformity.
Yes. If a casino has a flawed RNG script that exhibits modulo bias, a player who knows the biased numbers can adjust their bet sizing to focus exclusively on the favored outcomes, effectively wiping out the house edge and turning the game into a positive expected value scenario.