How the dice work on bkgn.net
Last updated
Short answer: the dice are rolled in your browser, the bot can't see them in advance, and every game can be replayed from its seed. "The dice are rigged" is the most common complaint about online backgammon. Studies that recorded every roll on large sites found the dice fair: people remember the painful rolls and forget the rest. We still think you should be able to check.
How a game's dice are made
- When a game starts, your browser asks its built-in cryptographic generator (
crypto.getRandomValues) for a fresh 128-bit seed. Nothing about you goes into it. - Every roll in that game is computed from the seed and the roll number with SHA-256. The result is a stream of random bytes.
- Bytes are turned into dice with rejection sampling: a byte from 0 to 251 gives a die of (byte mod 6) + 1; bytes 252 to 255 are skipped. 252 is divisible by 6, so every face has exactly the same chance. (Simply taking "byte mod 6" would make 1s to 4s very slightly more likely than 5s and 6s.)
- The opening roll uses the same stream: one die for each player, re-rolled on a tie.
What the bot can and can't see
The computer opponent runs in a separate background thread. It receives only the current position and the roll it has to play. It never receives the seed, so it cannot know what you or it will roll next. The dice are never tuned to make games closer, to let you win, or to keep you playing.
Replaying a game
The seed is shown during and after each game. Because the rolls follow from the seed alone, anyone with the seed gets exactly the same sequence of dice, so the game can be replayed and checked roll for roll. Paste a seed below to list the opening roll and the first 200 turns' rolls (turns count both players in order; a game rarely goes past 100).
What this proves, and what it doesn't
This shows that a game's dice depend only on a seed made in your own browser, that the conversion to dice has no bias, and that the bot cannot read ahead. It relies on the code running in your browser being the code described here, which you can read in your browser's developer tools. For games between two people on different devices, a server will need to take part in the dice, and a stronger scheme (commit and reveal) is planned for that.
Fair dice still feel unfair sometimes
- Any specific number (say, a 6 on at least one die) comes up in 11 of 36 rolls, about 31%.
- Doubles come up 1 time in 6.
- Against a home board with two open points, you fail to enter from the bar 4 times in 9 (both dice must miss: 4/6 × 4/6 = 16/36).
After each game, the review shows a luck figure: how much the dice helped or hurt each side, measured against an average roll. It's the honest answer to "did I lose on the dice or on my moves?"
Further reading: Youngerman, "Online backgammon dice" (bkgm.com).