I am working on making a RPG and am trying to understand the statistics of the core mechanic so I can determine how effective leveling and bonuses will be.

Right now the core mechanic is a skill die based mechanic where you roll a d4, d6, d8 or d10 based on your skill opposed by either a DC set by the story teller (1-10) or the result of another die via an opposed roll. (a DC is the number that the die must roll at least, for example if the die need to roll a 6 or higher then the DC would be 6)

I am experimenting with rolling two dice and picking the higher of the two, however I don't know how to make a statistical model for this. Especially due to the fact that I am planning on using exploding dice. (Exploding dice occur when you roll the highest possible number on the die. If this occurs you roll the die again, adding it to the total value of the die roll. This can continue an infinite number of times theoretically.)

I would very much appreciate some help on coming up with a formula for this. I want to set up an excel sheet to compare different bonus methods so I would really like something where I can put the formula in and tweak it instead of just probabilities listed.

  • 2
    $\begingroup$ this might be better answered on the stack exchange maths site math.stackexchange.com $\endgroup$ – Phil Oct 26 '12 at 0:08
  • 2
    $\begingroup$ Welcome! Excited to hear that you're working on a game. However, I've voted to close this question. The reason for this is that questions here should be specific and answerable. Right now all we can do with this question is refer you to an outside source. Perhaps a better tack would be to begin creating your statistical model and ask us if you run into any issues. You've told us very little about your system and even less about what you're trying to accomplish with your mechanics. Short of linking you to anydice or similar there isn't much more we can give you. $\endgroup$ – wax eagle Oct 26 '12 at 1:18
  • 5
    $\begingroup$ On that note, I encourage you to keep asking question as you encounter specific issues in your game development endeavors. As Phil mentions sometimes the math might get out of scope for this site and Cross Validated or Mathematics might be better places to ask, but most specific questions regarding rpg development are on topic here and we'd love to help! $\endgroup$ – wax eagle Oct 26 '12 at 1:19

There are three questions posed here. In all but one (unusual) case, we can derive closed formulas or answers that require a small, fixed number of sums: no double, triple, or even quadruple loops are necessary. I will restate and then answer each question in turn, providing worked examples in each case.

(As an aside: why should we care about efficiency in these calculations? Because these dice are the building blocks of what might become extremely complex game scenarios. It can be attractive to study many variations of the game, which may require considering millions of slightly different dice. Such analysis becomes possible when the basic probability calculations are very fast.)

Several variations of each question are considered, depending on whether the dice are fair or not and, when contestants are competing head-to-head, whether they are using the same dice or not. Considering unfair dice is very general, because it includes situations where players sum the values on two or more independent throws of dice.

Only a few basic rules of probability are needed to address almost all these situations. First, the chances of mutually exclusive outcomes are added. When these outcomes exhaust all possibilities, the chances must sum to $1$. Second, the chances of independent outcomes are multiplied. In one case (at the very end), a fundamental rule of conditional probability is needed: the chance of an event $A$ equals the chance of some other event $B$ times the conditional probability of $A$ given $B$.

  1. What is the chance that a $d_n$ will equal or exceed a DC? For example, what is the chance that a $d_8$ will equal or exceed $5$?

    If the die is fair, the chance of each outcome is $1/n$ and $n-DC+1$ of those outcomes equal or exceed $DC$, whence the chance is $(n-DC+1)/n$. For example, a $d_8$ has a $(8-5+1)/8$ = $50$% chance of equaling or exceeding $5$.

    If the die is loaded (or is constructed by summing other dice), let $p_i$ be the chance it shows the value $i$. The chance of equalling or exceeding $DC$ is obtained by summing over those mutually exclusive outomes, $\sum_{i\ge DC}p_i$. The chance of falling below the $DC$ is, similarly, $p_1+p_2+\ldots+p_{DC-1}$, which I will call $P_{DC}$ (with a capital $P$). These numbers (which are cumulative chances) show up again below.

  2. What is the chance that a $d_n$ will equal or exceed a $d_m$?

    When the dice are the same, then $n=m$ and the chance they are both $i$ equals $p_i^2$. Thus, considering the mutually exclusive outcomes of two $1$'s, two $2$'s, etc., the chance of a tie is $\Pr(tie)=\sum_{i=1}^n p_i^2$. Because the players are evenly matched, they split the chances of winning outright, whence the chance of a win equals $(1 - \Pr(tie))/2$. For example, the chance of a tie between two $d_8$'s is $\sum_i (1/8)^2$ = $1/8$ and (therefore) the chance of a win is $(1-1/8)/2$ = $7/16$ and the chance of a loss also is $7/16$.

    When the dice are different, there's usually no other option than looking at all possibilities. But this does not require $m n$ calculations. Let's assume--without any loss of generality--that $m \le n$. Let the probabilities for the $d_n$ be $p_1, p_2, \ldots, p_n$ and let the probabilities for the $d_m$ be $q_1, q_2, \ldots, q_m$. The chance that the $d_n$ shows $i$ and the $d_m$ shows $j$ is therefore $p_i q_j$.

    • The chance of a tie is computed much as before, but the sum must stop at the highest possible common value: $\Pr(tie) = \sum_{i=1}^m p_i q_i$. That takes $O(m)$ calculations (specifically, $m$ multiplications and $m-1$ additions).

    • The chance that the $d_m$ wins can be found by imagining a table of all outcomes, with the $d_n$ designating the rows and the $d_m$ the columns. The $d_m$ wins in all the above-diagonal cells. Those can be thought of as comprising $m-1$ vertical strips. The strips form a staircase: there is just one cell in the strip for an outcome of $2$ (because only a $1$ is smaller), there are two cells for $3$, and so on. Let $P_i = p_1 + p_2 + \cdots + p_{i-1}$ be the chance that the $d_n$ is less than $i$. Summing over the strips gives $\sum_{i=2}^m P_i q_i$ for the chance that the $d_m$ wins. Computing the $P_i$ requires only $O(m)$ work ($m-2$ additions) and computing the sum is again $O(m)$ ($m-1$ multiplications and $m-2$ additions). Finally, the chance the $d_n$ wins is obtained by noting the three chances--win, tie, lose--must sum to 1. Thus, we obtain all the desired probabilities with $2m-1$ multiplications, $3m-4$ additions, and a subtraction--and $m$ is the size of the smaller die.


    Let's pit a fair $d_4$ against a sum of a $d_2$ and a $d_3$, which is a form of a loaded $d_5$. Here $n=5$ and $m=4$. We can work out the chances for this $d_5$ easily; they are $p_1=0$, $p_2=p_5=1/6$, and $p_3=p_4=1/3$, which can be abbreviated by the vector $(0,1/6,1/3,1/3,1/6)$. Thus the cumulative sums $P_i$ are $(0,1/6,1/2)$ (we stop at $1/2$ because that is all we will need; the next two cumulative sums are $5/6$ and $1$). The probabilities for the fair $d_4$ are, of course, $(1/4,1/4,1/4,1/4)$. Thus the chance of a tie is $(0(1/4) + (1/6)(1/4) + (1/3)(1/4) + (1/3)(1/4)$ = $5/24$. The chance of a $d_4$ win is $(0)(1/4) +(1/6)(1/4) + (1/2)(1/4)$ = $1/6$. Therefore the chance that the $d_5$ wins equals $1 - (5/24 + 1/6)$ = $5/8$. We did not have to compute all $6\times 4=24$ cases to get these answers.

  3. How do we deal with exploding dice?

    Let's consider only two equivalent dice (although they do not have to be fair), say with probabilities $(p_1,p_2,\ldots,p_n)$. The only time an "explosion" might make a difference is when both dice roll an $n$; then the procedure repeats. Let $z$ be the chance of a tie. Then either a tie occurs at a value less than $n$--which has a chance of $\sum_{i=1}^{n-1}p_i^2$ of happening--or else both dice roll $n$ (which has a chance $p_n^2$ of happening) and a tie subsequently occurs, with chance $z$. Solving this equation gives $z = \sum_{i=1}^{n-1}p_i^2 / (1 - p_n^2)$. Because the dice are equivalent, then--reasoning as before--the two players split the remaining chances equally between winning and losing.

    (The case of two inequivalent exploding dice--especially when each has a different maximum value at which it explodes--can be solved, but because infinitely many outcomes are possible, efficient solutions require manipulating the probability generating functions and, ultimately, making numerical approximations.)


    Let the two players use a sum of two fair $d_6$'s, exploding on the maximum value of $12$. The chance vector for one roll is $(0,1/36,2/36,3/36,4/36,5/36,6/36,5/36,4/36,3/36,2/36,1/36)$. Then $\sum_{i=1}^{12-1}p_i^2$ = $0^2 + (1/36)^2 + \cdots + (2/36)^2$ = $145/1296 \approx 0.11188$ and $1 - p_n^2$ = $1 - (1/36)^2$ = $1295/1296$. Therefore the chance of a tie is $(145/1296) / (1295/1296)$ = $29/259 \approx 0.11197$. The chance of a win equals $(1 - 29/259)/2$ = $115/259 \approx 0.444015$. Evidently the explosion is of little consequence. In fact, our general formula makes it evident that when $p_n^2$ is small, the explosion will hardly affect the chances of winning or tying (although of course it can appreciably affect the expected value of the die). For instance, if $p_n$ is as large as $1/5$, explosion will multiply the chance of a tie by about $0.96$, hardly any reduction at all.


AnyDice has a lot of tools for dice probability. Check out the documentation.

For instance, output d4 > d4 gives the probability of one players d4 beating another. There's a 37.5% chance that the first player will win the roll in that situation.

  • $\begingroup$ This doesn't appear to answer the question, which asks for a "formula." $\endgroup$ – whuber Jan 3 '16 at 17:28
  • 1
    $\begingroup$ This answer was pre-migration and is for game designers who want to understand the probability curves quickly without having to learn the statistics terms. $\endgroup$ – Simon Gill Jan 3 '16 at 22:24

Tabular method

For two dice, the simplest way to do it is to do a 2-dimensional grid, then count the number of results.

   A 1 2 3 4   Chances
 B ----------- Of 24
 1 | 1 2 3 4 | 1
 2 | 2 2 3 4 | 3
 3 | 3 3 3 4 | 5
 4 | 4 4 4 4 | 7
 5 | 5 5 5 5 | 4
 6 | 6 6 6 6 | 4

One can unwrap such a table into a second table...

   AB 1 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 6 6 6 6   Chances
 C   -------------------------------------------------- of 4*5*6
 1 |  1 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 6 6 6 6 | 1 (1-0)
 2 |  2 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 6 6 6 6 | 7 (8-1)
 3 |  3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 6 6 6 6 | 19 (27-16)
 4 |  4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 6 6 6 6 | 37 (64-27)
 5 |  5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 | 36 4*(25-16)
 6 |  6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 | 44 4*(36-25)
 7 |  7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 | 24 
 8 |  8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 | 24 

Formulaic method

Given A ≤ B, and any N ≤ A, odds of N on higher of 1dA and 1dB are (N^2)-((N-1)^2)/(A*B), and any A

For 3d, where N ≤ A ≤ B ≤ C, odds of N are ((N^3)-((N-1)^3))/(A*B*C).
IIRC, Where A < N ≤ B ≤ C, odds of N are A*((N^2)-((N-1)^2))/(A*B*C).
IIRC, where A ≤ B < N ≤ C, odds of N are A*B/(A*B*C)

For 4d, it should be... N ≤ A ≤ B ≤ C ≤ D, chance(N)= ((N^4)-(N^3))/(A*B*C*D)
A ≤ N ≤ B ≤ C ≤ D, chance(N)= A*((N^3)-(N^2))/(A*B*C*D)
A ≤ B ≤ N ≤ C ≤ D, chance(N)= A*B*((N^2)-(N^1))/(A*B*C*D)
A ≤ B ≤ C ≤ N ≤ D, chance(N)= A*B*C/(A*B*C*D)

And so on...

Programmatic method

It's possible to use nested for/next loops. I'll provide a python example, because it's cheap, easy, and has nifty tools like .sort()...

T = 0
R = [0,0,0,0,0,0,0,0,0,0,0] 
' R needs one more "0," than the largest number of sides
' we set up a for line for each die, with the possible results in the entries.
For A in [1,2,3,4]:
    for B in [1,2,3,4,5,6]:
        for C in [1,2,3,4,5,6,7,8]:
            for D in [1,2,3,4,5,6,7,8,9,10]:
                ' now we do actual work...
                temp = [0,0,0,0]
                ' reset temp
                ' we've just loaded the current die's values into array Temp
                ' we've just put them into order
                n = temp[3]
                ' we get the high die
                R[n] += 1
                ' we increment the count for a result of n
                T += 1
                ' we count the total iterations.
X = 0
' we're setting our output loop next, and it uses X as a counter
for Y in R:
    print X, Y
    ' print current entry labeled. 
    X += 1
    ' increment X

Similar methods can be used in many languages, but for this kind of calculation I use Python for its really robust arrays.

  • 1
    $\begingroup$ Probably you wrote it that way for a reason, but anyway, the Python code could be simplified somewhat or totally rewritten without the nesting $\endgroup$ – Stuart Oct 26 '12 at 15:49
  • $\begingroup$ @Stuart Human intelligibility is why. Your reduction is, while slick, much less intelligible to non-hard-core programmers, and that's counter productive. $\endgroup$ – aramis Jan 25 '14 at 12:45
  • $\begingroup$ using max(A, B, C, D) is less intelligible than making a temporary list of zeroes, changing the zeroes to the loop variables, sorting the list and taking the highest value from it? $\endgroup$ – Stuart Jan 26 '14 at 13:33
  • $\begingroup$ @stuart: It is if you need "keep 2". Your method is less intelligible and less useful for a broad spectrum of potential situations. $\endgroup$ – aramis Jan 9 '16 at 12:20

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.