# How do I mathematically find this distribution?

I roll 10d6. I can then reroll any ones or twos. Then, I can reroll any ones. What is the distribution of the number of sixes I will have?

• Welcome! Is there an actual RPG situation behind this? I am not sure whether this is off topic here, but you should (also) try the mathematics SE. May 24 '20 at 7:53
• Well, we answered anyway :) Happy gaming! May 24 '20 at 8:09
• Welcome to RPG.SE! Take the tour if you haven't already, and check out the help center for more guidance.
– V2Blast
May 24 '20 at 9:15
• Could you add the context in which you'd make this roll (say the game system)? May 24 '20 at 15:38

# It's a binomial distribution

The binomial distribution (Wikipedia) is a probability distribution for the number of "successes" in $$\n\$$ independent trials or experiments, with each experiment having a constant probability $$\p\$$ to be a success.

It might be hard to understand why this is a binomial distribution – after all, the re-rolls sound like we are repeating stuff conditionally, which in turn sounds like we are not in the realm of "independent trials" anymore. However, this is superficial! Let me re-frame the problem a bit:

• We roll the die thrice, always, and simply ignore the re-rolls if they "shouldn't have happened"
• Instead of 10d6, we roll 10d216 (note: 216 = 6³)
• Each side on this 216 represents a unique ordered series of outcomes of three consecutive d6 rolls, so the die has sides $$\(1, 1, 1) , (1, 1, 2) , \ldots , (6, 6, 6)\$$
• A roll of this d216 is clearly equivalent to rolling a d6 three times
• In order to count as a success, one of the following must be true:
1. The first number of the result is a 6 (six without a re-roll)
2. The first number of the result is a 1 or 2, and the second is a 6 (six on the first re-roll)
3. The first number of the result is a 1 or 2, the second number is a 1, and the third number is a 6 (six on the second re-roll)

It's quite easy to see that this 10d216 method is equivalent to just rolling 10d6 with re-rolls, but it establishes a way to think of the re-rolls as a part of a single experiment. The following reasoning for finding $$\p\$$ applies whether you think of the d216 or a plain old 3d6 per experiment.

In order to get $$\p\$$ we need to count how many of the 216 possible outcomes match at least one of the conditions. Thankfully, all of the three conditions are disjoint – they cannot occur at the same time, so they can be treated independently and simply added together to get $$\p\$$.

Condition 1 is simple: each of 1, 2, 3, 4, 5 and 6 is equally likely to be the first number rolled on the 3d6, so the probability of condition 1 being met is $$\\frac{1}{6} = \frac{36}{216}\$$.

Condition 2 requires us to get one of two specific numbers first, and then a 6. Therefore, the probability of condition 2 being met is $$\\frac{2}{6} \cdot \frac{1}{6} = \frac{12}{216}\$$.

Condition 3 requires us to get one of two specific numbers first, then a 1, then a 6. The probability is therefore $$\\frac{2}{6} \cdot \frac{1}{6} \cdot \frac{1}{6} = \frac{2}{216}\$$.

Adding these up, we get $$p = \frac{36+12+2}{216} = \frac{50}{216}$$

Now, you have $$\n = 10\$$ since you're performing this experiment ten times, and $$\p ≃ 0.231\$$. You can use these as the parameters for the binomial distribution functions. Or just plug it in Wolfram Alpha like this: https://www.wolframalpha.com/input/?i=binomial+distribution+n%3D10+p%3D0.231

The expected/average value, due to the linearity of expectation, is $$\10p\$$ sixes.

• You know, I was really skeptical when I saw '10d216'.... Well done. May 24 '20 at 22:10

As kviiri and Szega have noted, this is a binomial distribution.

Why? Because each rolled (and possibly rerolled) die is an independent Bernoulli trial — i.e. an experiment that has only two possible outcomes (success or failure) and which always has the same probability of producing a success. And the total number of successes from $$\n\$$ repeated Bernoulli trials follows a binomial distribution.

In other words, we can rephrase your dice rolling mechanic in the following equivalent manner:

1. You roll a single six-sided die. If it rolls 1 or 2, you reroll it. If the reroll is a 1, you reroll it again. If at any point in this process you roll a 6, you count this roll as one success.
2. You repeat the process above ten times, counting the number of successes.

The first step above is the Bernoulli trial. It produces one of two results: success (you roll a 6) or failure (you don't roll a 6). And it always does this with the same probability. Repeating this trial ten times thus yields a binomially distributed number of successes.

In your original description of the process, you're carrying out all 10 trials at the same time, using 10 different dice. But it should hopefully be obvious that this doesn't change the distribution of the results, since the numbers rolled on different dice don't affect each other in any way.

We can even calculate the actual success probability for this Bernoulli trial:

• Obviously, the probability of rolling a 6 directly on the first roll is 1/6.
• The probability of rolling 1 or 2 on the first roll and then a 6 on the reroll is 1/3 × 1/6 = 1/18.
• The probability of rolling 1 or 2 on the first roll, 1 on the second and 6 on the last roll is 1/3 × 1/6 × 1/6 = 1/108.

All of the three possible events described above are mutually exclusive, so we can simply add up their probabilities to get the total probability of rolling a 6 on one die, i.e. $$\frac16 + \frac{1}{18} + \frac{1}{108} = \frac{18 + 6 + 1}{108} = \frac{25}{108} = 0.23\overline{148}.$$

In particular, this implies that the expected average number of successes for 10 rolls is 10 × 25/108 ≈ 2.3148.

PS. I couldn't resist the temptation to verify this calculation using AnyDice. To model the reroll mechanic, I used a generic helper function from this answer:

function: ROLL:n reroll BAD:s as REROLL:d {
if ROLL = BAD { result: REROLL }
result: ROLL
}


Using the function, we can easily obtain the distribution of results for one rerolled die:

DIE: [d6 reroll {1,2} as [d6 reroll 1 as d6]]
output DIE named "d6, reroll 1 or 2, then reroll 1"


I assigned this distribution to a custom die (imaginatively named DIE) so I could use it to calculate the success / failure distribution for a single trial (i.e. the probability of rolling a 6 on a single rerolled d6):

TRIAL: DIE = 6
output TRIAL named "probability of rolling 6 with this reroll mechanic"


Here, TRIAL is a biased two-sided die (or coin) that rolls 1 if the Bernoulli trial is a success and 0 if it's not. Using this biased die, we can get the distribution of successes over 10 trials simply by rolling it 10 times:

output 10dTRIAL named "number of 6s for 10d6 with this reroll mechanic"


The results, plotted as bar charts, look like this:

• Isn't 0.23 the chance of rolling a six on a single die with the above mechanic? May 25 '20 at 0:52
• @NomadMaker: Yes, and I thought I said so, but reading it again, I can see how it could be read differently. I added a few words, hopefully it's clearer now. May 25 '20 at 0:54

# Still binomial

What you propose only changes the probability of rolling a 6 on every individual die, but they still remain independent of each other. As such it will be binomial, just as it would be without the rerolls.

The new probability of rolling a six is: 1/6 + 1/3 * (1/6 + 1/6 * 1/6) = 23.15% (rounded)

• @Medix2 You mean that I should embed an image of the PDF? The distribution is stated explicitly. May 24 '20 at 10:41