How a local die is rolled, and why every face is equally likely
Published · By TG, the site operator
On this board a roll is a number from 1 to 6, and in a local game the browser chooses it. The rule is short enough to read in the source, so a reader who asks whether the die is fair can check the code instead of taking the site's word for it.
The function draws four bytes from the browser's cryptographic random source and reads them as one unsigned 32-bit integer, a value from 0 to 4,294,967,295. If the value is 4,294,967,292 or more, it is thrown away and a new draw is made. Otherwise the die shows the value modulo 6, plus 1.
The discard step is the important part. Six does not divide 4,294,967,296 evenly; the remainder is 4. Taking the remainder of every draw would make the low faces slightly more likely. The code stops the accepted range at 4,294,967,292, which is exactly 715,827,882 groups of six, so each face is reached by the same number of accepted values.
The source of the numbers matters too. The MDN reference for crypto.getRandomValues describes the output as random in the cryptographic sense: a pseudo-random generator seeded with enough entropy, which the page calls suitable for cryptographic purposes. A single call is capped at 65,536 bytes, far more than the one four-byte value the die needs.
Each roll is a fresh draw. A six in one turn says nothing about the next roll, and a long run of ones is no sign the die is biased. The computer uses the same function when it is its turn, so both colours roll from one source.
Online games work differently. The guide says the server produces the die and your browser only sends the request to roll, so this explanation covers local games only.
Roll the die in a local game →
What fairness does and does not give you
A fair die does not make a game fair. It means that before the rules start, every number has a one-in-six chance. The rest of the game then decides how much a number is worth: a one may be useless while every token is in the yard, and a six may be wasted when three sixes in a row pass the turn.
So the useful question is not whether the die is fair but what a given number lets you do. The guide lists the house rules that turn a roll into a move, and the earlier posts on this site work out the odds for particular positions.
Practise it
- Roll the die in a local game and note the first ten faces. Ten rolls cannot test a die, which is why the arithmetic above is the better check.
- Before each roll, ask which tokens could move with each face. The die is only half of the decision.
The code is in app.js, in the function that returns a number from 1 to 6. Read it once; the discard step is a single loop condition.
Sources
- Crypto: getRandomValues() method (MDN Web Docs) — MDN Web Docs
- Ludo: local dice and rules, the guide — Ludo
- Ludo: application source (die roll function) — Ludo
Written by the operator of this site from the sources listed above. Spotted a mistake? Email warmeve.label@gmail.com and it will be corrected.