I’m contemplating programming an RPG where you roll N 6-sided dice to use a skill (the value of N comes from a statistic, and I might allow it to be as high as 10). A 5 or a 6 is a success (for a 1/3rd chance of success with 1 die). A difficult task might require multiple successes to complete.
I’ve written a program to compute just how likely all these dice rolls are to succeed. However, I’ve done this by using what little I can remember about probabilities rather than computing every possibility.
Does the following pseudocode seem like it should be correct? It’s the probability of getting exactly J successes with I dice (not more or less).
Probability(J successes with I dice) = Probability(1 success with 1 die) * Probability(J - 1 successes with I - 1 dice) + Probability(1 failure with 1 die) * Probability(J successes with I - 1 dice)
Since I know the probability of success/failure with 1 die, this is the same as:
Probability(J successes with I dice) = 1/3 * Probability(J - 1 successes with I - 1 dice) + 2/3 * Probability(J successes with I - 1 dice)
Basically, it’s a recursive formula that figures that one die is either a success or not and then factors in the probabilities of getting the right number of successes in each case.
I’ve already written the program, and I’m pretty sure it’s correct. However, I wanted to check this with someone before posting the tables on my website. I considered writing a program to use brute force to check all these numbers, but, for all I know, my brute force program might turn out to be wrong. I would rather just verify that my math is right.
I’ve pasted the tables below, though the headers aren’t formatted properly after being pasted.
Number of Successes (exact)
Dice 0 1 2 3 4 5 6 7 8 9 10
1 66.666% 33.333% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000%
2 44.444% 44.444% 11.111% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000%
3 29.629% 44.444% 22.222% 3.703% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000%
4 19.753% 39.506% 29.629% 9.876% 1.234% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000%
5 13.168% 32.921% 32.921% 16.460% 4.115% 0.411% 0.000% 0.000% 0.000% 0.000% 0.000%
6 8.779% 26.337% 32.921% 21.947% 8.230% 1.646% 0.137% 0.000% 0.000% 0.000% 0.000%
7 5.852% 20.484% 30.727% 25.605% 12.802% 3.840% 0.640% 0.045% 0.000% 0.000% 0.000%
8 3.901% 15.607% 27.312% 27.312% 17.070% 6.828% 1.707% 0.243% 0.015% 0.000% 0.000%
9 2.601% 11.705% 23.411% 27.312% 20.484% 10.242% 3.414% 0.731% 0.091% 0.005% 0.000%
10 1.734% 8.670% 19.509% 26.012% 22.760% 13.656% 5.690% 1.625% 0.304% 0.033% 0.001%
To get the probability of at least J successes, I just added the relevant probabilities together, and created another table.
Number of Successes (at least)
Dice 0 1 2 3 4 5 6 7 8 9 10
1 100.000% 33.333% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000%
2 100.000% 55.555% 11.111% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000%
3 100.000% 70.370% 25.925% 3.703% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000%
4 100.000% 80.246% 40.740% 11.111% 1.234% 0.000% 0.000% 0.000% 0.000% 0.000% 0.000%
5 100.000% 86.831% 53.909% 20.987% 4.526% 0.411% 0.000% 0.000% 0.000% 0.000% 0.000%
6 100.000% 91.220% 64.883% 31.961% 10.013% 1.783% 0.137% 0.000% 0.000% 0.000% 0.000%
7 100.000% 94.147% 73.662% 42.935% 17.329% 4.526% 0.685% 0.045% 0.000% 0.000% 0.000%
8 100.000% 96.098% 80.490% 53.177% 25.864% 8.794% 1.966% 0.259% 0.015% 0.000% 0.000%
9 100.000% 97.398% 85.693% 62.282% 34.969% 14.484% 4.242% 0.828% 0.096% 0.005% 0.000%
10 100.000% 98.265% 89.595% 70.085% 44.073% 21.312% 7.656% 1.966% 0.340% 0.035% 0.001%