Tools and worked checks · 06 / 23
How a hash becomes a number, and where modulo bias comes from
A hash is 32 bytes with no meaning as a number. A game needs a number in a small range. The conversion between the two is a convention, and some conventions are slightly uneven.

Bytes to a number, step by step
This tool runs in your browser with the Web Crypto API. It sends nothing over the network and works offline once the page has loaded. Never paste a wallet secret phrase or a private key here or into any verifier. No check on this site needs one.
Free of charge, no account. Runs in any current web browser.
The result appears here.
Modulo bias, counted exactly
Choose how many bits the integer has and how many outcomes you want. The tool counts how many of the 2^bits inputs land on each outcome. Nothing is simulated.
The result appears here.
From 32 bytes to one integer
The usual convention reads four bytes as one unsigned integer with the first byte as the most significant. Take the digest of test vector V1, which begins fd3f9c65. Its first four bytes are 253, 63, 156, 101 in decimal, and 253 × 16777216 + 63 × 65536 + 156 × 256 + 101 = 4248804453. Call this integer u. It can be any of the 4294967296 values from 0 to 2^32 − 1.
From the integer to a range
Two methods are common. The first scales: divide u by 2^32 to get a fraction between 0 and 1, multiply by the range N and round down. Here 4248804453 / 4294967296 = 0.9892518756, and with N = 10000 the result is 9892. The second takes the remainder of u divided by N.
Some descriptions write the fraction as the first byte divided by 256, plus the second divided by 256², plus the third divided by 256³, plus the fourth divided by 256⁴. That sum is the same number as u / 2^32.
Where the bias comes from
There are 2^32 possible inputs and N outcomes. When N does not divide 2^32, the inputs cannot be shared out evenly, and some outcomes receive one input more than the others. With small integers the effect is easy to see. An 8-bit integer has 256 values. For N = 100, the remainders 0 to 55 each occur 3 times and the remainders 56 to 99 occur 2 times, so a low result is 50 % more likely than a high one.

| Bits | N | Inputs per unfavoured outcome | Inputs per favoured outcome | Favoured outcomes | Relative excess | Discarded by rejection |
|---|---|---|---|---|---|---|
| 8 | 6 | 42 | 43 | 4 | 2.38 % | 1.56 % |
| 8 | 37 | 6 | 7 | 34 | 16.7 % | 13.3 % |
| 8 | 100 | 2 | 3 | 56 | 50 % | 21.9 % |
| 16 | 37 | 1771 | 1772 | 9 | 0.0565 % | 0.0137 % |
| 16 | 10000 | 6 | 7 | 5536 | 16.7 % | 8.45 % |
| 32 | 37 | 116080197 | 116080198 | 7 | 0.000000861 % | 0.000000163 % |
| 32 | 52 | 82595524 | 82595525 | 48 | 0.00000121 % | 0.00000112 % |
| 32 | 10000 | 429496 | 429497 | 7296 | 0.000233 % | 0.00017 % |
| 32 | 1000000 | 4294 | 4295 | 967296 | 0.0233 % | 0.0225 % |
| 32 | 1000000000 | 4 | 5 | 294967296 | 25 % | 6.87 % |
At 32 bits and N = 10000, 7296 outcomes have 429497 inputs and the others have 429496. The relative excess is one part in 429496, which no record of play would reveal. The effect grows with N, as the last rows show, and a written specification ought to state the rule whatever its size. The scaling method has the same number of favoured outcomes. They are spread across the range, while the remainder method collects them at the low end.
Rejection sampling
The imbalance disappears if the inputs that cause it are thrown away. Compute the largest multiple of N that fits into 2^32 and call it the limit. An integer at or above the limit is discarded and the next four bytes are read. Every outcome then has the same number of accepted inputs.
function unbiased(nextUint32, n) {
const limit = 4294967296 - (4294967296 % n);
let u = nextUint32();
while (u >= limit) u = nextUint32();
return u % n;
}The cost is an occasional extra read. For N = 10000, 7296 of the 4294967296 possible reads are discarded. For N = 3000000000 the limit is 3000000000 and 30.2 % of reads are discarded, which is why test vector V5 on the methods page contains a skipped read. A verifier has to follow the same rule, or its byte positions drift after the first skip.
Shuffling a deck
A shuffle needs many numbers, each in a different range. The Fisher–Yates method walks from the last card to the second and swaps each card with one chosen from the positions up to and including its own. For 52 cards that is 51 picks, in ranges from 52 down to 2.
function shuffle(deck, pick) {
for (let i = deck.length - 1; i > 0; i--) {
const j = pick(i + 1);
[deck[i], deck[j]] = [deck[j], deck[i]];
}
return deck;
}Under a four-byte rule, 51 picks consume 204 bytes, more than one 32-byte digest holds. This is the reason the message in the verifier's scheme carries a round number: the stream continues with the digest of the next round. A shuffle that picks from the full range at every step does not give every order the same chance, even with unbiased numbers.
What testing standards say about scaling
Conversion rules are within the scope of laboratory testing. GLI-19 version 3.0, section 3.2.3, requires that “All scaling, mapping, and shuffling algorithms used shall be unbiased, as verified by source code review.” The Gambling Commission's RTS 7 guidance lists uniform distribution and unpredictability among the qualities an RNG should demonstrate and adds that any scaling should preserve them. More on that process is on the page about how RNGs are tested.
Questions people ask
Does modulo bias help a player?
No. At 32 bits, for every range from 2 to 50000 outcomes, a favoured outcome is more likely than an unfavoured one by at most one part in 85899, far too little to show in any session. The table above shows that the effect grows for very large ranges. In every case it leaves the house edge where it is. It matters as a question of correct specification.
Why are the bytes read with the first byte as the most significant?
It is a convention, called big-endian. The opposite order would work as well. What matters is that the operator's code and your check use the same one.
Is a float less exact than an integer here?
The four-byte fraction has 32 bits, which a double-precision number holds exactly. Our code still multiplies in whole numbers first and divides afterwards, so that large ranges are exact too.
Sources
- GLI-19, Standards for Interactive Gaming Systems, version 3.0 (Gaming Laboratories International, 17 July 2020). Chapter 3 holds the RNG requirements quoted on this site. A file named as a draft of version 4.0, dated 7 July 2026, is also on the GLI site; we describe version 3.0. Checked .
- Gambling Commission (Great Britain), Remote gambling and software technical standards, RTS 7: Generation of random outcomes. Published 2 February 2021, last updated 7 May 2024 according to the page. Checked .
How we checked: statements about a named body link to that body's own page and carry the date we read it. Numbers in worked examples are computed by the site's build from the formulas shown, with routines covered by its test suite.