A provably fair dice game commits the operator to a secret server seed by publishing its SHA-256 hash before any bet. Each roll is then derived from an HMAC-SHA256 of that seed, the player’s client seed and a nonce. Building it means getting three parts right: the commitment, the conversion from bytes to a roll, and the verifier. The conversion is where most defects hide, and a matching hash proves far less than the marketing around it suggests.
On this page
- Provably Fair Dice Games Commit to a Seed Hash Before Any Bet Is Placed
- How a Dice Roll Is Derived from HMAC-SHA256 Output and a Conversion Formula
- Modulo Bias Skews Dice Results Unless the Conversion Rejects Out-of-Range Values
- Operators Build Verification by Rotating Seeds and Shipping a Verifier Players Can Run
- What a Matching Hash Does Not Prove About a Casino’s Fairness
Provably Fair Dice Games Commit to a Seed Hash Before Any Bet Is Placed
The whole scheme rests on one ordering rule. The operator generates a server seed, publishes its SHA-256 hash, and only then accepts bets. The seed itself stays secret until it is retired, at which point the player can hash it and compare the result to the value shown earlier. If the two match, the operator used the seed it committed to.
Three inputs feed every roll, and each has a distinct job.
- Server seed: A random secret generated by the operator, typically 32 bytes from a cryptographically secure source and written as hex. It is the key that makes the roll unpredictable to the player while it stays hidden.
- Client seed: A string the player supplies or edits. It gives the player a say in the outcome, so the operator cannot have chosen the seed to suit a known input.
- Nonce: A counter that increments with every bet under the current seed pair. It makes each roll different even when both seeds stay the same, and it resets when the seeds rotate.
Why must the hash be fixed before the first bet? Consider the alternative. If an operator could pick or swap the server seed after seeing wagers, it could select a seed that makes the large bets lose and present it as chance. Publishing the hash first removes that option. SHA-256 is one-way, so the player cannot recover the seed from the hash, but the operator cannot produce a different seed that hashes to the same value. The commitment binds the operator without revealing anything useful.
The client seed completes the picture. The sequence is: the hash is displayed, the player may set a client seed, then bets begin. Neither side alone controls the HMAC input, which is what lets the player say the outcome was not arranged in advance.
Several small decisions here become disputes later if you leave them implicit:
- Hash input encoding: State whether the commitment is SHA-256 over the hex string as text or over the decoded raw bytes. Both are valid, but a player who guesses wrong sees a mismatch and assumes fraud.
- Hash display format: Use lowercase hex and say so.
- Nonce start: Say whether the first bet uses nonce 0 or 1.
- Next seed: Show the hash of the next server seed before the current one is revealed, so the commitment chain never has a gap.
None of this is difficult cryptography. The difficulty is operational discipline, because the commitment is only as good as the record of it. Our provably fair casino games development guide covers the wider game catalog, but dice is the cleanest place to get the primitives right first.
How a Dice Roll Is Derived from HMAC-SHA256 Output and a Conversion Formula
In the common layout, the roll starts as an HMAC-SHA256 with the server seed as the key and the client seed, nonce and a cursor as the message, joined by a delimiter such as a colon. HMAC itself is specified in RFC 2104 on HMAC, and every mainstream language has a tested implementation. Do not write your own. The exact message layout is yours to define, but you must publish it character for character.
The output is 32 bytes. Dice reads the first four of them and scales that number to a roll between 0.00 and 99.99, or in some published formulas 0.00 to 100.00. The conversion is a separate step from the HMAC, and it is the step players cannot reconstruct unless you document it.
A Floor-Based Conversion in Practice
One widely copied approach turns the four bytes into a float in the range zero to just under one. Each byte is divided by a rising power of 256 and the four results are summed. The roll is then floor(float × 10001) / 100. Because 10001 is the multiplier, this formula yields 10,001 possible outcomes, 0.00 through 100.00 inclusive. An implementation that scales to 10,000 outcomes instead stops at 99.99. Neither is wrong, but they are different games with different edge arithmetic, so the endpoints belong in your spec.
A quick illustration with made-up bytes, not real HMAC output. If the first four bytes are 0x80, 0x00, 0x00, 0x00, the float is exactly 0.5. Multiply by 10001 and you get 5000.5. The floor is 5000, and dividing by 100 gives a displayed roll of 50.00. If all four bytes are zero, the roll is 0.00.
Then comes the win condition. State whether a roll-over bet at a target of 50.00 wins on a roll strictly above the target or at or above it. This is a frequent source of one-hundredth-of-a-percent disagreements, and it changes the edge.
What a Verifier Does and Does Not Recompute
A generic verifier recomputes the HMAC and shows you the hex. That is all it can do without knowing your rules. The step from hex to displayed roll belongs to the operator, so the conversion has to be written down next to the tool, ideally with pseudocode and test vectors. A player who gets a 64-character string and no formula has verified nothing they can interpret.
You will also see examples online that use HMAC-SHA512, and others that use HMAC-SHA256. Current guides describe dice as HMAC-SHA256, but there is no single standard that settles it. What counts is the algorithm you publish and actually run. A verifier built for SHA-256 will return different bytes from your SHA-512 implementation, and the mismatch will look like cheating. Pick one, version it, and never change it silently for existing seeds.
Modulo Bias Skews Dice Results Unless the Conversion Rejects Out-of-Range Values
If you convert the four bytes with a plain modulo, you introduce a small but real skew. A four-byte value has 232 possibilities, which is 4,294,967,296. That number is not a multiple of 10,000. Dividing gives 429,496 full groups of 10,000 with a remainder of 7,296.
The consequence is arithmetic, not statistical. Under a modulo mapping, 7,296 of the 10,000 results can be produced by 429,497 different input values, and the other 2,704 by 429,496. Those extra preimages favor the lower results. The relative excess is roughly one part in 429,000, or about 0.0002 percent. No player will feel it, and no session of play will reveal it.
It still matters. Your product claim is that the process is verifiable and fair, and a known non-uniformity contradicts that claim in a way a mathematically inclined player can demonstrate in an afternoon. It also means that two bets sold with the same nominal edge, one roll-under and one roll-over, differ slightly in true probability. Scaling by multiplication, as in the floor-based formula above, does not escape this. Any mapping of 232 values onto 10,000 or 10,001 outcomes has to give some outcomes one more preimage than others, and the same pigeonhole logic applies.
Rejection Sampling
The standard fix is to throw away the values that cause the imbalance. Compute the largest multiple of 10,000 that fits in 232, which is 4,294,960,000. Take the four-byte value. If it is at or above that limit, discard it and read the next four bytes. Otherwise apply the modulo. Every outcome now has exactly 429,496 preimages.
A rejection happens about 7,296 times in 232 draws, so rarely that you will almost never see it. But the code path must exist and the verifier must replicate it. Since one HMAC output holds eight four-byte words, move through them in order, and if all eight are rejected, increment the cursor in the message and compute a fresh HMAC. Write that fallback into the published spec, even though it will almost never run.
A documented alternative is to draw a larger integer, for example eight bytes, and apply the modulo to that. The bias falls by many orders of magnitude but does not reach zero. If you take this route, say plainly that the bias is negligible rather than absent.
Testing Before Launch
Use three layers of testing, because each catches something the others miss:
- Exact enumeration: Loop over the full 232 input domain, apply your conversion, and count preimages per outcome. This takes minutes, and with rejection every outcome should show the same count. It is the only test that detects a bias this small.
- Distribution check: Generate tens of millions of rolls from random seed pairs, bin them, and run a chi-square test. This will not see a one-in-429,000 skew, because sampling noise swamps it. It will catch byte-order mistakes, off-by-one errors, a 100.00 that never appears or appears too often, and broken cursor handling.
- Cross-implementation vectors: Run the same seed, nonce and cursor inputs through your server code and an independent verifier written in another language, including boundary inputs such as all-zero and all-0xFF bytes.
The broader requirements for entropy, auditing and testing are covered in RNG in iGaming for B2B providers.
Operators Build Verification by Rotating Seeds and Shipping a Verifier Players Can Run
Most provably fair casinos include a built-in verifier and let players rotate their seeds. Rotation is the mechanism that makes verification possible, because the active server seed must stay secret while bets are being placed. When the player changes the client seed, the system reveals the previous server seed, starts a new seed pair using the hash already published for the next seed, and resets the nonce. After that, the player can check the old seed against its old hash and replay every bet made under it.
A player can therefore verify a roll without asking the casino anything, but only after the seed has been revealed and only if the formula is public. Before rotation, they can see the hash and their own nonce and nothing more. That is by design.
The Platform Work Behind It
The player-facing page is thin. Most of the effort sits in the back end.
- Seed generation: Draw server seeds from a cryptographically secure source such as the operating system’s random generator. Never derive them from timestamps, user IDs or a general-purpose pseudo-random function.
- Seed and hash history: Store every seed pair with its creation time, status (active or revealed), published hash and final nonce. The hash record should be append-only. Keep the unrevealed seed encrypted at rest with tightly limited access, since anyone who can read it can predict rolls.
- Nonce per bet: Increment the nonce in the same transaction that records the bet, so a crash or a retry can never skip, duplicate or reuse a value. Show the nonce on every bet in the history.
- Bet export: Let players download their bets as CSV or JSON, with client seed, nonce, server seed hash, revealed seed once available, target, direction and displayed roll. Support exports that span several seed pairs.
- Formula next to the verifier: Publish the message layout, algorithm, conversion, rejection rule, endpoints and win condition on the same page as the tool, with a version number and sample vectors.
- Versioning: If you change the conversion, keep the old verifier available for bets placed under the old rules.
The verifier itself should run in the browser, or be offered as a standalone open-source script, so the player is not trusting your server to report on your server. A verifier that calls your API for the answer verifies nothing. Show the two checks separately: first the hash comparison for the commitment, then the roll recomputation. Merging them into a single green tick hides what was actually tested.
Third-party verifiers exist and some are built to match a particular operator’s output, but they only work if your formula is identical to the one they implement. Do not assume that. Test against them if you intend to claim compatibility.
For the wider system, including how seed generation connects to game logic, wallets and audit logs, see our RNG engine service, which sits behind this kind of fairness design.
What a Matching Hash Does Not Prove About a Casino’s Fairness
A matching hash confirms one narrow thing: that a specific roll came from the seed the operator committed to, using the formula the operator published. It says nothing beyond that single round, and it is worth being exact about the limits, because players and some marketing copy treat a green tick as a verdict on the whole business.
| Question | Does a matching hash answer it? |
|---|---|
| Was this roll derived from the committed seed? | Yes |
| Was the operator’s conversion formula applied as published? | Yes, if the verifier implements that formula |
| Is the formula itself unbiased? | No, that needs analysis of the formula |
| Is the return to player what the operator states? | No |
| Are withdrawals paid promptly and in full? | No |
| Is the operator licensed and compliant? | No |
Take the return to player question. Hash verification does not tell you whether the stated RTP is correct, because it checks individual outcomes and not the payout table, the edge or the long-run distribution. An operator could publish a perfectly verifiable game with a larger edge than it advertises. Verification would pass every round.
Regulated markets handle the system-level question separately. Regulators such as the UK Gambling Commission require random number generators to be tested as part of licensing, and that testing looks at the generator and game behavior as a whole. Round-level verification is a complementary check that the player can run, and it does not replace independent RNG certification. Treat them as two different instruments.
Also be careful about how you describe the model’s reach. Provably fair checks test how one round was produced, and they have not become a universal industry standard. Implementations differ in algorithm, message layout and conversion, which is exactly why each operator has to document its own. A closed system is not automatically dishonest either, so avoid framing the model as the only trustworthy design. The scope is also narrow in practice. By some estimates, a casino lobby of nearly 3,000 games may have only 20 to 30 provably fair titles, mostly in-house originals such as dice, crash and similar formats.
The commitment also binds the seed sequence and not the operator’s behavior around it. It does not cover which bets are accepted, how accounts are restricted, or how winnings are paid. Say so in your documentation instead of letting players infer more.
What to Document Alongside the Verifier
- The algorithm and version, for example HMAC-SHA256, and a note that it will not change for live seeds.
- The exact message layout, delimiter, encodings and whether the nonce starts at 0 or 1.
- The byte-to-roll conversion, including the rejection rule and cursor behavior.
- The outcome range with its endpoints, such as 0.00 to 99.99 or 0.00 to 100.00.
- The win condition for roll-over and roll-under bets, and how payout and edge are calculated.
- How seeds rotate, when they are revealed, and how the next hash is shown in advance.
- Test vectors that a player or third-party developer can run.
- The RTP statement and the status of independent RNG testing, stated separately from the verifier.
- A change log for every revision to any of the above.
If a player can reproduce every roll from that page alone, and nothing on it claims more than the check proves, you have built what the model promises.
