How to generate a random number between 1 and 10 with a six-sided die?

Solution 1:

You may throw the die many ($N$) times, take the sum of the outcomes and consider the residue class $\pmod{10}$. The distribution on $[1,10]$ gets closer and closer to a uniform distribution as $N$ increases.


You may throw the die once to decide if the final outcome will be even or odd, then throw it again until it gives an outcome different from six, that fixes the residue class $\pmod{5}$. In such a way you generate a uniform distribution over $[1,10]$ with $\frac{11}{5}=\color{red}{2.2}$ tosses, in average.


If you are allowed to throw the die in a wedge, you may label the edges of the die with the numbers in $[1,10]$ and mark two opposite edges as "reroll". In such a way you save exactly one toss, and need just $\color{red}{1.2}$ tosses, in average.


Obviously, if you are allowed to throw the die in decagonal glass you don't even need the die, but in such a case the lateral thinking spree ends with just $\color{red}{1}$ toss. Not much different from buying a D10, as Travis suggested.


At last, just for fun: look at the die, without throwing it. Then look at your clock, the last digit of the seconds. Add one. $\color{red}{0}$ tosses.

Solution 2:

Write out the base-$6$ decimals of $\frac{0}{10}$ through $\frac{10}{10}$.

$$\begin{array}{cc} \frac{0}{10} & = 0.00000000\dots\\ \frac{1}{10} & = 0.03333333\dots\\ \frac{2}{10} & = 0.11111111\dots\\ \frac{3}{10} & = 0.14444444\dots\\ \frac{4}{10} & = 0.22222222\dots\\ \frac{5}{10} & = 0.30000000\dots\\ \frac{6}{10} & = 0.33333333\dots\\ \frac{7}{10} & = 0.41111111\dots\\ \frac{8}{10} & = 0.44444444\dots\\ \frac{9}{10} & = 0.52222222\dots\\ \frac{10}{10} & = 1.00000000\dots\\ \end{array}$$

Treat rolls of a $6$ as a $0$. As you roll your $6$-sided die, you are generating digits of a base-$6$ decimal number, uniformly distributed between $0$ and $1$. There are $10$ gaps in between the fractions for $\frac{x}{10}$, corresponding to the $10$ uniformly random outcomes you are looking for. You know which outcome you are generating as soon as you know which gap the random number will be in.

This is kind of annoying to do. Here's an equivalent algorithm:

Roll a die $$\begin{array}{c|c} 1 & A(0,1)\\ 2 & B(1,2,3)\\ 3 & A(4,3)\\ 4 & A(5,6)\\ 5 & B(6,7,8)\\ 6 & A(9,8)\\ \end{array}$$ $A(x,y)$: Roll a die $$\begin{array}{c|c} 1,2,3 & x\\ 4 & A(x,y)\\ 5,6 & y\\ \end{array}$$ $B(x,y,z)$: Roll a die $$\begin{array}{c|c} 1 & x\\ 2 & C(x,y)\\ 3,4 & y\\ 5 & C(z,y)\\ 6 & z\\ \end{array}$$ $C(x,y)$: Roll a die $$\begin{array}{c|c} 1 & x\\ 2 & C(x,y)\\ 3,4,5,6 & y\\ \end{array}$$

One sees that:

  • $A(x,y)$ returns $x$ with probability $\frac35$ and $y$ with probability $\frac25$.
  • $B(x,y,z)$ returns $x$ with probability $\frac15$, $y$ with probability $\frac35$, and $z$ with probability $\frac15$.
  • $C(x,y)$ returns $x$ with probability $\frac15$ and $y$ with probability $\frac45$.

Overall, it produces the $10$ outcomes each with $\frac1{10}$ probability.

Procedures $A$ and $C$ are expected to require $\frac65$ rolls. Procedure $B$ is expected to require $\frac23 \cdot 1 + \frac13 (1 + E(C)) = \frac75$ rolls. So the main procedure is expected to require $\frac23 (1 + E(A)) + \frac13(1 + E(B)) = \frac{34}{15} = 2.2\overline{6}$ rolls.

Solution 3:

Here is an alternative method, rather different from the ones described earlier, and the only one which approaches the maximum theoretical efficiency.

Let $a=0 $ and $b=10$. We are going to imagine that these describe the set of real numbers between 0 and 10, including 0 but not including 10, which we write as $[0,10)$. Each die roll narrows the set, and when the set is narrow enough, we have our answer.

The procedure for narrowing down the interval is as follows:

  1. Roll a die, producing an integer $d$ between 1 and 6.
  2. Cut the interval $[a, b)$ into six equal parts and choose the $d$th part, throwing away the rest:
    1. $\ell \leftarrow \frac16(b-a)\quad$ (the interval had length $b-a$ before; $\ell$ is one-sixth of this size)
    2. $a \leftarrow a + (d-1)\ell$
    3. $b\leftarrow a+\ell\quad$ (the new interval now has length $\ell$)
  3. If at this point the integer parts of $a$ and $b$ are the same, then the result is that integer part; stop. If not, return to step 1. (We write the integer part of $x$ as $\lfloor x \rfloor$.)

For example, let's see what happens when we throw 3, then 5.

$$\def\db#1{\color{darkblue}{#1}}\begin{array}{ccc|cccc|c} [a, b) & \db\ell & \text{roll} & \text{new } a & \text{new } b & \lfloor a\rfloor & \lfloor b \rfloor & \lfloor a\rfloor = \lfloor b \rfloor \\\hline [0,10)&\db{\frac{10}6} & 3 & 0 + 2\cdot\db\ell = \frac{20}{6} & \frac{20}{6} + \db{\frac{10}6} = \frac{30}6 & 3 & 5 & \text{no} \\ \left[\frac{20}{6},\frac{30}6\right) & \db{\frac{10}{36}}& 5 & \frac{20}6 + 4\cdot\db\ell = \frac{160}{36}& \frac{160}{36} + \db{\frac{10}{36}} = \frac{170}{36} & 4 & 4 & \text{yes} \end{array} $$

The integer parts at the end are both 4, so the result is 4. This time the result took only 2 throws, but it can take more:

$$\begin{array}{ccc|cccc|c} [a, b) & \db\ell & \text{roll} & \text{new } a & \text{new } b & \lfloor a\rfloor & \lfloor b \rfloor & \lfloor a\rfloor = \lfloor b \rfloor\\\hline [0,10)&\db{\frac{10}6} & 5 & 0 + 4\cdot\db\ell = \frac{40}{6} & \frac{40}6 + \db{\frac{10}6} = \frac{50}6 & 6 & 8 & \text{no} \\ \left[\frac{40}6,\frac{50}6\right)&\db{\frac{10}{36}} & 2 & \frac{40}6 + 1\cdot\db\ell = \frac{250}{36} & \frac{250}{36} + \db{\frac{10}{36}} = \frac{260}{36} & 6 & 7 & \text{no} \\ \left[\frac{250}{36},\frac{260}{36}\right)&\db{\frac{10}{216}} & 2 & \frac{250}{36} + 1\cdot\db\ell = \frac{1510}{216} & \frac{1510}{216} + \db{\frac{10}{216}} = \frac{1520}{216} & 6 & 7 & \text{no} \\ \left[\frac{1510}{216},\frac{1520}{2166}\right)&\db{\frac{10}{1296}} & 6 & \frac{1510}{216} + 5\cdot\db\ell = \frac{9110}{1216} & \frac{9110}{1296} + \db{\frac{10}{1296}} = \frac{9120}{1296} & 7 & 7 & \text{yes} \\ \end{array} $$

Had we rolled another 2 at the end instead of a 6, we would still have had $\lfloor a\rfloor = 6$ and $\lfloor b\rfloor = 7$ and we would have had to continue. Any other roll, such as the 6 we actually got, would stop the process.

What is happening here is that we imagine we are choosing a real number from $[0,10)$, and we will then throw away the fraction part of this real number. Each die roll determines a base-6 digit from $\{0,1,2,3,4,5\}$. The sequence of digits rolled can be concatenated together with a fractional point to produce the base-6 version of a decimal fraction between 0 and 1. If we convert this fraction to base 10, then take its tenths-place digit, we will have the uniformly distributed result we want.

The calculations with $[a,b)$ are keeping track of our uncertainty in the real number we are generating from die rolls. To generate the entire real number, we would have to roll the die forever, But we don't need the entire real number. Rolling a die narrows down the interval of uncertainty by a factor of 6; the interval becomes $\frac 16$ as wide. (This is what $\ell$ is tracking.) When the interval has shrunk sufficiently, it is likely to lie entirely within an interval $[0.p000\ldots, 0.p999\ldots)$ and at that point we know the tenths-place digit, which is all we need.

We can't guarantee to bound the number of die rolls in advance (no method can, as explained in the comments) but for producing large numbers of digits, this method produces results with the theoretically optimal average number of rolls, which is $$\frac{\log 10}{\log 6} \approx 1.2851,$$ far better than any of the methods described elsewhere in this thread. For generating a single decimal digit, we still need at least two rolls. But suppose we want to generate 10 decimal digits. In that case instead of stopping when $a $ and $b$ agree in their first decimal place, we stop when they agree to 10 decimal places. This takes, on average, a bit more than $10\frac{\log 10}{\log 6} $ rolls, say around 13 or 14. For example, suppose we roll $1,5,3,5,4,2,2,6,6,2,4,5,3,1$. This narrows down $[a,b)$ to $$\left[\frac{9707055060}{78364164096}, \frac{9707055070}{78364164096}\right) \approx \left[.1238710981, .1238710982\right)$$ so our 14 rolls have in this case generated 8 decimal digits $1\,2\,3\,8\,7\,1\,0\,9\,8$ (and almost a ninth, which is either 1 or 2), an efficiency of greater than $\frac{14}8=1.75$ rolls per digit.

Solution 4:

Purely FTR. I believe (in a, let's say, marketing sense),

the most simple, understandable method is this:

Roll once: odd means it's a number 1-5, even means it's a number 6-10.

Roll again: very simply, if you get a six ignore that and keep rolling until you get a not-six.

You have your answer.

Note that in any, say, casino or similar setting - even just a board game with kids -

this is the only approach that is so easily understandable - to non-mathematicians - that it's the way to go.

It's worth remembering that only one person in a gazillion understands distributions: I bet that out of 1000 adults, maybe 1 would understand that rolling two dice does not give you "a 'random' number between 1 and 12."

Solution 5:

  1. Roll a d6. Now you have a random number in $[1;6]$, in level distribution.
  2. Roll a d6 again. If the result is odd, add 6 to the previous result. Now you have a random number in $[1;12]$, in level distribution.
  3. If the result is 11 or 12, then restart the whole process agan (from 1).
  4. If you are here, now you have a random number in $[1;10]$, in level distribution.

P.s. Yes, it is a level distribution. See the comments below.