Can a 7-sided die be simulated by rolling two 5-sided dice, discarding and re-rolling when their total exceeds $7$?

283 Views Asked by At

Regarding simulating a 7-sided die roll with two 5-sided dice: I understand the question "Seven-sided dice from five-sided dice with finite rolls" and this answer to it. But,

Why can't you just add $\operatorname{rand}(5)+\operatorname{rand}(5)$, then discard and re-roll if the result is greater than $7$?

I understand that the worst-case runtime is $O(\infty)$, but the answer linked above also has $O(\infty)$ worst-case.

Note: This is my first stack-exchange question, so please feel free to give feedback on question-asking style.

3

There are 3 best solutions below

9
On BEST ANSWER

You cannot add two $5$ rolls and then subtract off the sum to get $1$ as the minimum roll because there will be an unequal number of ways to get different results. For instance, if you sum two $5$-die rolls and then subtract $1$, there is only one way to get a final $1$ (roll 1 and roll 1). But there are two ways to get a final $2$ (roll 1 and roll 2 OR roll 2 and roll 1). It is twice as likely you'll get a final $2$ than a final $1$ by that approach.

If you allow (possibly infinite) re-rolls (as you apparently do), there are many fair methods to make a $7$-sided die from a $5$-sided one.

Here is one of the simplest, conceptually:

Method 1: Roll the $5$-sided die $7$ times in sequence and record which roll came out with the highest value (if first roll, then 1; if second roll then 2, ...). If there are ties for the maximum, then start over.

This is not very efficient, though.

Method 2: A slightly more efficient method is like the above, but if there is a tie for maximum value, then look for the sequence position where you got the minimum value, and use that as the index to the final value. If you get ties for both the maximum and the minimum, then start over.

You can do slightly better than this, with...

Method 3: As in Method 2, but if you get a tie on the maximum and on the minimum, look for the position that has the value 1 less than the maximum on the rolls (and it is not the minimum). If there are several of those, then re-start.

And you can construct ever-more complicated and slightly more efficient methods...

Method 4: Find the sequence location of a $5$. If there are none or more than $1$, then find the sequence location of a $4$. If there are none or more than $1$, the find the sequence location of a $3$.... If all this fails, start over.

4
On

The sums of two random numbers in $\{1,\ldots,5\}$ are not evenly distributed in $\{1,\ldots,7\}$. In fact there is no way to get a sum of $1$, and $3$ is twice as likely as $2$.

EDIT: Since $5^6 \equiv 1 \mod 7$, here's a fairly efficient way. Take $6$ rolls of the $5$-sided die, subtract $1$ from each, and interpret the result as a base-$5$ number from $0$ to $5^6-1$. If the result is $5^6-1$ (i.e. the $6$ rolls were $(5,5,5,5,5,5)$, do over: otherwise take the number mod $7$, add $1$ and there is your result.

0
On

If you have a red and green five sided die, there are $25$ results from rolling the two of them. You can assign three results to each of the $7$ numbers, which leaves a $\frac 4{25}=16\%$ chance of a reroll. For example, $(1,1),(1,2),(2,1)$ become $1,\ (2,2),(2,3),(3,2)$ become $2$ and so on. If you throw away the information of which roll you had to reroll, you expect to roll about $1.19$ times to get a result. You can do a bit better if you keep track of which of the four rerolls you got because you can pair one or two of the potential rerolls on the second round with each of the four from the first and get seven more throws that you resolve. That takes more keeping track of than I think is worthwhile.