Dice guide
Wild West Dice: check a roll yourself
The Wild West name is decoration for this page; the rules underneath are generic number dice. Treat this guide as a short exercise. By the end you will have checked a commitment and recomputed one roll with your own tools.
What you need
- A revealed server seed. For this exercise:
wildwest-server-e83d. - The commitment you saw before play, the SHA-256 hash of that seed.
- Your client seed, here
my-own-seed-55, and the nonce of the roll, here 9. - Any tool that computes SHA-256 and HMAC-SHA256. A few lines of Python are enough.
Step 1: check the commitment
Hash the revealed server seed with SHA-256. You should get f54675364fedd74e8e26d4af5a378d42ab1c38bd665aa9527573db4f8ade5b55. If that matches the hash shown before play, the seed was fixed in advance. If it does not match, stop: the rest of the check is meaningless, because the seed could have been chosen after the fact.
Step 2: build the message and the digest
Join the client seed, the nonce and a round counter of 0 with colons: my-own-seed-55:9:0. Compute HMAC-SHA256 with the server seed as the key. The first 8 hex digits of the digest are fbdb9e36.
Step 3: turn the digits into a roll
Read those 8 digits as a hexadecimal number, divide by 2 to the power 32, multiply by 10,000, round down and divide by 100. The roll is 98.38. Compare it with the bet you made. A bet under 60.00 would be a loss.
| Server seed (revealed later) | wildwest-server-e83d |
|---|---|
| Commitment shown before play: SHA-256(server seed) | f54675364fedd74e8e26d4af5a378d42ab1c38bd665aa9527573db4f8ade5b55 |
| Client seed : nonce : round | my-own-seed-55:9:0 |
| HMAC-SHA256(server seed, message) | fbdb9e36f02f48b653caccb3a7f5307b8f59e1ae07508065f003e3c24eeb2cda |
| First 4 bytes (8 hex digits) | fbdb9e36 = 4,225,474,102 |
| Float = value / 2^32 | 0.9838198549 |
| Dice roll = floor(float x 10,000) / 100 | 98.38 |
| Bet 'under 60.00' | loss |
One common construction, shown for teaching. Real services document their own message format; check theirs before verifying.
The same check as a script
import hashlib, hmac, math
server = "wildwest-server-e83d"
client = "my-own-seed-55"
nonce = 9
print(hashlib.sha256(server.encode()).hexdigest())
msg = f"{client}:{nonce}:0".encode()
d = hmac.new(server.encode(), msg, hashlib.sha256).hexdigest()
roll = math.floor(int(d[:8], 16) / 2**32 * 10000) / 100
print(d[:8], roll)
Run it and compare the output with the table. If your numbers match, your tools work the same way as the example.
When the numbers do not match
- Check the message format. A space, a missing round counter or a different separator changes everything.
- Check which value is the key. Swapping key and message gives a different digest.
- Check the byte order and how many bytes are read.
- Check the service's own documentation. The construction here is a common teaching example, not a universal standard.
A successful check shows that a roll followed from seeds fixed in advance. It says nothing about future rolls and does not reduce the edge. More background is on the hash fairness guide.