How to create a biased number generator using a pair of six sided dice

algorithm, math, puzzle

Solution

Assume two dice: one white one black.

- Roll the two dice giving you two numbers from 1 to 6;

- Create a new number: 6 * (white dice - 1) + black dice

- This number is between 1 and 36. If it's above 30 go to 2 and repeat;

Now you have what you need:

- 1-12 = 1 (12/30 = 40%)

- 13-21 = 2 (9/30 = 30%)

- 22-27 = 3 (6/30 = 20%)

- 28-30 = 4 (3/30 = 10%)

What you need is not 4 possible outcomes but 10 because that can represent the weighted result you want. Two dice can produce 36 possibilities in a number of ways but what you need is 10 or a multiple of 10, such as the above.

The only downside to this method is that it's probabilistic (meaning you could sit there rerolling 31+ forever technically) but I'm not convinced a deterministic and accurate solution exists.

Problem

What is the most efficient way to use a pair of six sided dice to generate a random number in [1, 4] unevenly: it should produce 1 in 40% of the time, 2 in 30%, 3 in 20%, and 4 in 10%. Please justify the correctness of the method and give an algorithm. Dice could be of different colors. Note: the only random number generators available are two differently coloured six-sided dice.

Original source

Related problems