Verifiable Randomness Documentation

Verifiable Randomness Systems

View the Project on GitHub blockrand-api/blockrand-js

Unbiased Dice Rolls: Why Dice Are Almost Always Wrong

The Problem

Rolling a dice sounds trivial.

Most developers assume that generating a random number between 1 and 6 is as simple as:

  1. Generate a random number
  2. Apply modulo
  3. Add 1

This approach is wrong in most real systems — and the bias it introduces is subtle enough that it often goes unnoticed, yet significant enough to matter in games, betting systems, and simulations.

This document explains:

The Naive Dice Roll

A very common implementation looks like this:

  1. Generate a random integer R
  2. Compute R % 6
  3. Add 1 to shift into [1, 6]

At first glance, this seems reasonable.

It is not.

Where the Bias Comes From

Most random number generators produce values in a fixed range, for example:

These ranges are not divisible by 6.

That means:

This is called modulo bias.

A Concrete Example

Assume a generator produces numbers from 0 to 9 (10 total values).

If you compute R % 6, the mapping looks like this:

0 → 0

1 → 1

2 → 2

3 → 3

4 → 4

5 → 5

6 → 0

7 → 1

8 → 2

9 → 3

Outcome frequencies:

This is not uniform.

The same problem exists with real RNG ranges — just harder to see.

Why This Matters in Practice

Bias in dice rolls leads to:

Even a tiny bias becomes meaningful when:

The Correct Solution: Rejection Sampling

To generate an unbiased dice roll:

  1. Define a range that is evenly divisible by 6
  2. Discard any random values outside that range
  3. Apply modulo only to accepted values

This ensures:

Conceptual Algorithm

Let the RNG produce values in [0, M)

  1. Compute maxMultiple = (M / 6) * 6
  2. If R >= maxMultiple, reject and retry
  3. Otherwise, return (R % 6) + 1

This guarantees uniform distribution.

Performance Concerns (and Why They Don’t Matter)

A common worry is that rejection sampling is “slow”.

In reality:

Correctness matters far more than theoretical micro-optimizations.

Deterministic and Verifiable Dice Rolls

In verifiable systems, dice rolls should be:

This means:

Dice Beyond D6

The same principles apply to:

The number of sides changes — the math does not.

The Key Insight

A dice roll is only fair if every outcome is equally reachable from the entropy source.

Modulo alone does not guarantee this.

Rejection sampling does.

Summary