1

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?

9
  • 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")? – Mycroft Feb 2 at 1:26
  • 1
    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 Feb 2 at 1:37
  • 1
    I know your using python but there is a useful website here anydice.com. You can work out many dice probability there and with a bit of coding create some complicated combinations and rules. – StartPlayer Feb 2 at 10:07
  • 1
    Are you looking for exactly i successes or at least i successes? – L. Scott Johnson Feb 2 at 12:58
  • 1
    @DavidSiegel OP already provides an example which is equivalent to yours and answers your question. – Benjamin Cosman Feb 2 at 15:27
3

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

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

7
  • 1
    If you haven't seen "choose" before, see en.wikipedia.org/wiki/Combination. It's math.comb in Python – Benjamin Cosman Feb 1 at 23:41
  • 1
    @John Thanks for the pretty picture :) – Benjamin Cosman Feb 2 at 21:24
  • @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 Feb 3 at 0:15
  • 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 Feb 3 at 0:20
  • 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 Feb 3 at 0:22
2

I used [Any Dice] 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

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

2
  • 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 Feb 3 at 0:24
  • 1
    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 Feb 3 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.