I am trying to create a calculator to solve a dice-roll problem in a role playing game that I play. Essentially, various character classes can attack a sleeping dragon with their own series of dice, ex:

  • An orc might be able swing an axe for 1d32 (one 32 sided dice-roll) damage in one turn

  • An elf might shoot two arrows and slingshot in one turn, doing 2d19 + 1d12 damage

If they don't kill the dragon in one turn, it will wake up and instantly kill them.

What I'm trying to find is this:

Given a particular probability threshold $p$, and a series of attack dice $x_1, x_2, \ldots, x_n$, what is the maximum HP the dragon can be at to satisfy $chanceToKillDragon \ge p$?


My elf rolls for 2d23 + 1d12 damage in one turn. Given that $p=0.50$, he should only attack dragons with $hp \le 31$. If the dragon was at 32 hp, my elf's chance to kill the dragon (roll a 32 or higher) would be 46.22%, which is smaller than the given $p=0.50$, so should not be done. 31 is the highest HP for the kill chance to be >50%.

Anyone have any ideas how I could go about calculating this? Currently I'm using an online dice roll calculator and just repeatedly inputting numbers by trial and error, but I would like to have a direct formula to calculate the number directly.

Any help would be greatly appreciated!

  • $\begingroup$ I am not familiar with this notation of dice. What does 2d23 mean? $\endgroup$ Commented Sep 2, 2019 at 19:05
  • $\begingroup$ 2d23 means two 23 sided dice are rolled $\endgroup$
    – Lunaris
    Commented Sep 2, 2019 at 19:25
  • $\begingroup$ Go to anydice.com, enter output 2d23+1d12 (or any other combination of dice) in the command pane, click "Calculate", click "Table" or "Export" after View and "At Least" after Data. Scroll down until you find the last percentage probability that is equal to $p$ or greater. This was the first hit in my web search, so there may be even better calculators out there, but this one seemed adequate. $\endgroup$
    – David K
    Commented Sep 2, 2019 at 20:02
  • $\begingroup$ You can also produce the same results with an Excel spreadsheet, or you could write your own calculator if you know a little programming. But there isn't a "nice" formula that you can easily write and plug in numbers to get an exact solution, like the formula to solve a quadratic equation. $\endgroup$
    – David K
    Commented Sep 2, 2019 at 20:08

1 Answer 1


Let $x_i$ denote the number of sides of the $i$-th attack dice used and suppose you use $n$ dices. The damage done solely by dice $i$ is a random variable with uniform distribution on $\{1, \ldots, x_i\}$, i.e., assumes each value on this set with equal probability $1/x_i$. Thus, you have that the maximum damage is $\sum_{i=1}^n x_i$ and the minimum damage is $n$. Any value on the range $R = [n, \sum_{i=1}^n x_i] \cap \mathbb{Z}$ has positive probability. To find out the precise probability of getting $r \in R$, you must sum over all possible combinations of dice that sum $r$.

More precisely, let $X_i$ be the random variable that represents the outcome of dice $i$. Since all dice are independent and uniform on their respective ranges, we have $$ P[(X_1, \ldots, X_n) = (r_1, \ldots, r_n)] = \prod_{i=1}^n \frac{1}{x_i}, $$ and notice that the right hand side does not depend on the specific values of $r_i$. We have that \begin{align*} P\left[ \sum_{i=1}^n X_i = r \right] &= \sum_{\substack{(r_1, \ldots, r_n);\\ \sum r_i = r}} P[(X_1, \ldots, X_n) = (r_1, \ldots, r_n)] \\ &= \left( \prod_{i=1}^n \frac{1}{x_i} \right) \cdot \#\left\{(r_1, \ldots, r_n); \sum r_i = r\right\} \end{align*} and analogously we have \begin{align*} P\left[ \sum_{i=1}^n X_i \geq r \right] &= \left( \prod_{i=1}^n \frac{1}{x_i} \right) \cdot \#\left\{(r_1, \ldots, r_n); \sum r_i \geq r\right\} \end{align*} Your problem asks to find the minimum $r(p)$ such that \begin{align*} P\left[ \sum_{i=1}^n X_i \geq r \right] &\geq p. \end{align*} By the reasoning above, we can translate this problem into a counting problem. You just need to compute $$ \# \{ (r_1, \ldots, r_n);\ 1 \le r_i \le x_i, \sum r_i \geq r \} $$ However, as mentioned in the comments, although you could write a formula for this in terms of binomial numbers I do not think that this formula would be very useful to you. For instance, a similar problem is to show $$ \# \{ (r_1, \ldots, r_n);\ 0 \le r_i, \sum r_i = r \} = \binom{r+n-1}{r} $$ and a small variation of it states that $$ \# \{ (r_1, \ldots, r_n);\ 1 \le r_i, \sum r_i = r \} = \# \{ (r_1, \ldots, r_n);\ 0\le r_i, \sum r_i = r - n \} =\binom{r-1}{r-n} $$ Introducing restrictions from above for the $r_i$ and afterwards summing for possible values of $r$ will get messy.

I do not know if your question emphasizes the theoretic point of view or if you are just interested in a practical one. It appears that there are already some sites that do this work for you; if you know how to program, it might be interesting to write one program by yourself to do this computation.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .