<p>P(i successes) = ((# of ways to get i 6s and no 5s) + (# of ways to get i-1 6s and some 5s)) / 6^n</p>
<p>(# of ways to get i 6s and no 5s) = (n choose i) * 1^i * 4^(n-i) [pick which dice must be 6s, 1 way for each of those to be a 6, 4 ways for each of the others to be neither 6 nor 5]</p>
<p>(# of ways to get i-1 6s and some 5s) = (n choose i-i) * 1^(i-1) * (5^(n-(i-1)) -
4^(n-(i-1))) [pick which dice must be 6s, 1 way for each of those to be a 6, 5 ways for each of the others to be non-6 except then we're overcounting by the 4^(n-(i-1)) ways that they are ALL neither 6 nor 5]</p>
<p>Dropping the unnecessary powers of 1, overall your probability can be computed exactly as:</p>
<p><a href="https://i.sstatic.net/LUK5R.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LUK5R.png" alt="ImageOfEquationFromWolframAlpha" /></a></p>
<p>[Note: I am using the convention that (n choose -1)=0, unlike Python's math.comb which does not allow negative inputs.]</p>

CC BY-SA 4.0
2021-02-01T23:41:06.477Z
If you haven't seen "choose" before, see https://en.wikipedia.org/wiki/Combination. It's math.comb in Python
Benjamin Cosman
CC BY-SA 4.0
2021-02-03T00:15:06.690Z
@Benjjamin Cosman, I think I see what you're  getting at, and I think you are on the right track, but there's still something wrong or I'm not interpreting you right. Here's the Python code I've got:
Tommy McGuire
CC BY-SA 4.0
2021-02-03T00:20:56.777Z
pSixes = comb(n, i)   * pow(1/6, i)   * (    pow(4/6, n - i))

    pBonus = comb(n, i-1) * pow(1/6, i-1) * (1 - pow(4/6, n - (i - 1)))

    result[i] = pSixes + pBonus

For 3 dice, that produces P(1 success) = 0.925925925925926, P(2 successes) = 0.33333333333333337, and P(3 successes) = 0.032407407407407406, ...
Tommy McGuire
CC BY-SA 4.0
2021-02-03T00:22:45.443Z
Which doesn't add up to 1.0 and doesn't match @StartPlayer's results (or my manual 3 dice attempt). I think something is wrong with the P(i-1 6s and some 5s) expression.
Tommy McGuire
CC BY-SA 4.0
2021-02-03T16:20:00.663Z
Oops; fixed. I've now checked that this one gives the same answer as @StartPlayer (and adds up to 1 :) )
Benjamin Cosman
CC BY-SA 4.0
2021-02-03T19:17:02.583Z
That is great! I never would have come up with that.  Thanks!
Tommy McGuire
CC BY-SA 4.0
2021-02-01T23:39:19.783Z
2021-02-03T17:52:22.073Z
2021-02-03T17:52:22.073Z
Benjamin Cosman
<p>I used <a href="https://anydice.com/program/204b1" rel="nofollow noreferrer">[Any Dice]</a> website to work this out.</p>
<p>The code below is probably not the cleanest but I only learned this site today. The function below will count 1 success if at least one 5 and add to that how many sixes rolled.  This is getting results of to 5d6.</p>
<p><a href="https://i.sstatic.net/yqerL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yqerL.png" alt="enter image description here" /></a></p>
<pre><code>function: contains VALUES:s in SEQUENCE:s {
 FIVES: 0
 SIXES: 0
 loop P over {1..#VALUES} {
 if (5 = SEQUENCE) {
  if FIVES = 0 {
   FIVES: 1
  }
 }
  SIXES: SIXES + (P@VALUES = SEQUENCE)
 }
 result: FIVES + SIXES
}

output [contains { 6 } in d6]
output [contains { 6 } in 2d6] 
output [contains { 6 } in 3d6] 
output [contains { 6 } in 4d6] 
output [contains { 6 } in 5d6] 
</code></pre>
<p>These are the results that I've formatted to be a bit more readable than the anydice website gives me. If you roll 1d6 the chance of 1 success (A  6 or 5) is 33.3%</p>
<p>If you roll 3d6. the chance of 2 successes is 18.05% (that's either 2 6s and no 5s or one 6 and at least one 5)</p>
<blockquote>
<p>1d6
<br>0 success, 66.6666666667 <br>1 success,33.3333333333</p>
<p>2d6
<br>0 success, 44.4444444444 <br>1 success, 47.2222222222 <br>2 success,8.33333333333</p>
<p>3d6
<br>0 success, 29.6296296296 <br>1 success, 50.462962963 <br>2 success, 18.0555555556 <br>3 success, 1.85185185185</p>
<p>4d6
<br>0 success, 19.7530864198 <br>1 success, 48.225308642 <br>2 success, 26.2345679012 <br>3 success, 5.4012345679 <br>4 success, 0.385802469136</p>
<p>5d6
<br>0 success, 13.1687242798 <br>1 success, 43.4799382716 <br>2 success, 31.9573045267 <br>3 success, 9.90226337449 <br>4 success, 1.4146090535 <br>5 success, 0.0771604938272</p>
</blockquote>

CC BY-SA 4.0
2021-02-03T00:24:24.313Z
Thanks for that! I wrote the 3 dice case manually, and it matches with your results. The problem is that once you get up to 8 or 9 dice, it's too slow (and I've forgotten how to get multiple dice loops :-)).
Tommy McGuire
CC BY-SA 4.0
2021-02-03T09:47:22.777Z
The 1 dice case was clearly correct and I drew about a 6x6 grid to check 2d6 results were correct as well.  An advantage of this site is you can write code to check and kind of odds.  if you have a bag or 7 tokens and two are "success" you can work that out as well by saying d7 as a 'dice'.    It takes a bit of coding and the site docs seem clear enough.
StartPlayer
CC BY-SA 4.0
2021-02-02T12:30:47.430Z
2021-02-03T14:21:40.533Z
2021-02-03T14:21:40.533Z
StartPlayer
<p>I am trying to figure out probability for a game using 6-sided dice. The basic idea is that the player rolls <em>n</em> dice and gets a success for each 6 rolled. So far, so simple; I'm using Python's scipy.binom.pmf function which gives the probability of rolling <em>i</em> successes on <em>n</em> dice with a given chance of success, 1/6 in this case.</p>
<p>But the game offers a &quot;bonus&quot;. With the bonus, in addition to 6s being successful, <strong>one</strong> 5 in the roll is also a success. (So a roll of 2, 3, 5, 5, 6, 6 would be two successes normally, but three with the bonus.)</p>
<p>How can I compute the probability of <em>i</em> successes on <em>n</em> dice with this bonus condition?</p>

CC BY-SA 4.0
2021-02-02T01:26:19.117Z
It is unclear to me when the "bonus" applies.  Is it decided before the roll (like "roll with advantage" in D&D), or is it something that applies based on the outcome of the roll (like "if there's a natural 6, then one 5 can count as a success as bonus")?
Mycroft
CC BY-SA 4.0
2021-02-02T01:37:10.640Z
Do yu mean that m**exactly-- one 5 is a bonus success, ort at least  one 5? How many successes is a roll of 6 6 5 5 4 3?
David Siegel
CC BY-SA 4.0
2021-02-02T10:07:01.667Z
I know your using python but there is a useful website here https://anydice.com.   You can work out many dice probability there and with a bit of coding create some complicated combinations and rules.
StartPlayer
CC BY-SA 4.0
2021-02-02T12:58:13.310Z
Are you looking for exactly *i* successes or at least *i* successes?
L. Scott Johnson
CC BY-SA 4.0
2021-02-02T15:27:01.967Z
@DavidSiegel OP already provides an example which is equivalent to yours and answers your question.
Benjamin Cosman
CC BY-SA 4.0
2021-02-02T18:31:13.153Z
@Mycroft, the bonus is decided before the roll, as in "6 dice, with a bonus" or "5 dice, no bonus."
Tommy McGuire
CC BY-SA 4.0
2021-02-02T18:32:09.840Z
@DavidSiegel At least one 5 is one bonus. In your example, that would be 3 successes.
Tommy McGuire
CC BY-SA 4.0
2021-02-02T18:33:16.557Z
@L.ScottJohnson, exactly *i* successes.
Tommy McGuire
<dice><probability>
Probability of i event_A and j event_B on n dice
Tommy McGuire
# Probability of i event_A and j event_B on n dice

(Asked by: username_0 on 2021-02-01)

I am trying to figure out probability for a game using 6-sided dice. The basic idea is that the player rolls *n* dice and gets a success for each 6 rolled. So far, so simple; I'm using Python's scipy.binom.pmf function which gives the probability of rolling *i* successes on *n* dice with a given chance of success, 1/6 in this case.

But the game offers a "bonus". With the bonus, in addition to 6s being successful, **one** 5 in the roll is also a success. (So a roll of 2, 3, 5, 5, 6, 6 would be two successes normally, but three with the bonus.)

How can I compute the probability of *i* successes on *n* dice with this bonus condition?

**Tags:** dice, probability

> **Comments:**
> **username_1**: It is unclear to me when the "bonus" applies.  Is it decided before the roll (like "roll with advantage" in D&D), or is it something that applies based on the outcome of the roll (like "if there's a natural 6, then one 5 can count as a success as bonus")?  
> **username_2**: Do yu mean that m**exactly-- one 5 is a bonus success, ort at least  one 5? How many successes is a roll of 6 6 5 5 4 3?  
> **username_3**: I know your using python but there is a useful website here https://anydice.com.   You can work out many dice probability there and with a bit of coding create some complicated combinations and rules.  
> **username_4**: Are you looking for exactly *i* successes or at least *i* successes?  
> **username_5**: @username_2 OP already provides an example which is equivalent to yours and answers your question.  
> **username_0**: @username_1, the bonus is decided before the roll, as in "6 dice, with a bonus" or "5 dice, no bonus."  
> **username_0**: @username_2 At least one 5 is one bonus. In your example, that would be 3 successes.  
> **username_0**: @username_4, exactly *i* successes.  

---

## 2 answers

### Answer by username_5 on 2021-02-01. Score: 3 | Accepted answer

P(i successes) = ((# of ways to get i 6s and no 5s) + (# of ways to get i-1 6s and some 5s)) / 6^n

(# of ways to get i 6s and no 5s) = (n choose i) \* 1^i \* 4^(n-i) [pick which dice must be 6s, 1 way for each of those to be a 6, 4 ways for each of the others to be neither 6 nor 5]

(# of ways to get i-1 6s and some 5s) = (n choose i-i) \* 1^(i-1) \* (5^(n-(i-1)) -
4^(n-(i-1))) [pick which dice must be 6s, 1 way for each of those to be a 6, 5 ways for each of the others to be non-6 except then we're overcounting by the 4^(n-(i-1)) ways that they are ALL neither 6 nor 5]

Dropping the unnecessary powers of 1, overall your probability can be computed exactly as:

[![ImageOfEquationFromWolframAlpha](https://i.sstatic.net/LUK5R.png)](https://i.sstatic.net/LUK5R.png)

[Note: I am using the convention that (n choose -1)=0, unlike Python's math.comb which does not allow negative inputs.]

> **Comments:**
> **username_5**: If you haven't seen "choose" before, see https://en.wikipedia.org/wiki/Combination. It's math.comb in Python  
> **username_0**: @Benjjamin username_5, I think I see what you're  getting at, and I think you are on the right track, but there's still something wrong or I'm not interpreting you right. Here's the Python code I've got:  
> **username_0**: pSixes = comb(n, i)   * pow(1/6, i)   * (    pow(4/6, n - i))      pBonus = comb(n, i-1) * pow(1/6, i-1) * (1 - pow(4/6, n - (i - 1)))      result[i] = pSixes + pBonus  For 3 dice, that produces P(1 success) = 0.925925925925926, P(2 successes) = 0.33333333333333337, and P(3 successes) = 0.032407407407407406, ...  
> **username_0**: Which doesn't add up to 1.0 and doesn't match @username_3's results (or my manual 3 dice attempt). I think something is wrong with the P(i-1 6s and some 5s) expression.  
> **username_5**: Oops; fixed. I've now checked that this one gives the same answer as @username_3 (and adds up to 1 :) )  
> **username_0**: That is great! I never would have come up with that.  Thanks!  

---

### Answer by username_3 on 2021-02-02. Score: 2

I used [[Any Dice]](https://anydice.com/program/204b1) website to work this out.

The code below is probably not the cleanest but I only learned this site today. The function below will count 1 success if at least one 5 and add to that how many sixes rolled. This is getting results of to 5d6.

[![enter image description here](https://i.sstatic.net/yqerL.png)](https://i.sstatic.net/yqerL.png)

```
function: contains VALUES:s in SEQUENCE:s {
 FIVES: 0
 SIXES: 0
 loop P over {1..#VALUES} {
 if (5 = SEQUENCE) {
  if FIVES = 0 {
   FIVES: 1
  }
 }
  SIXES: SIXES + (P@VALUES = SEQUENCE)
 }
 result: FIVES + SIXES
}

output [contains { 6 } in d6]
output [contains { 6 } in 2d6] 
output [contains { 6 } in 3d6] 
output [contains { 6 } in 4d6] 
output [contains { 6 } in 5d6] 

```

These are the results that I've formatted to be a bit more readable than the anydice website gives me. If you roll 1d6 the chance of 1 success (A 6 or 5) is 33.3%

If you roll 3d6. the chance of 2 successes is 18.05% (that's either 2 6s and no 5s or one 6 and at least one 5)

> 1d6
>   
> 0 success, 66.6666666667   
> 1 success,33.3333333333
>
> 2d6
>   
> 0 success, 44.4444444444   
> 1 success, 47.2222222222   
> 2 success,8.33333333333
>
> 3d6
>   
> 0 success, 29.6296296296   
> 1 success, 50.462962963   
> 2 success, 18.0555555556   
> 3 success, 1.85185185185
>
> 4d6
>   
> 0 success, 19.7530864198   
> 1 success, 48.225308642   
> 2 success, 26.2345679012   
> 3 success, 5.4012345679   
> 4 success, 0.385802469136
>
> 5d6
>   
> 0 success, 13.1687242798   
> 1 success, 43.4799382716   
> 2 success, 31.9573045267   
> 3 success, 9.90226337449   
> 4 success, 1.4146090535   
> 5 success, 0.0771604938272

> **Comments:**
> **username_0**: Thanks for that! I wrote the 3 dice case manually, and it matches with your results. The problem is that once you get up to 8 or 9 dice, it's too slow (and I've forgotten how to get multiple dice loops :-)).  
> **username_3**: The 1 dice case was clearly correct and I drew about a 6x6 grid to check 2d6 results were correct as well.  An advantage of this site is you can write code to check and kind of odds.  if you have a bag or 7 tokens and two are "success" you can work that out as well by saying d7 as a 'dice'.    It takes a bit of coding and the site docs seem clear enough.  

---

