What algorithm could be used to determine distribution of possible results of the rolls of multiple variable-sided dice?

636 Views Asked by At

In a recent project, I came across a problem where we needed to provide an end user with the distribution of likelihoods that certain sums of rolls would appear.

The dice rolled would be given as a sum of dice in standard dice notation (i.e. 3d6+4d8-3 - "the sum of three independent six-sided die rolls plus the sum of four independent eight-sided die rolls minus three"). However, converting this algorithmically into a distribution was immensely challenging - we still haven't found a way to go about this issue aside of calculating every possible combination (which is bad, as we sometimes have very large sets of numbers).

Is there an efficient way to determine the likelihood, or do we have to find every combination?

1

There are 1 best solutions below

3
On BEST ANSWER

Expanding the comments to an answer:

  • Denote the probability, that you get sum $a$ with probability $p$, by the generating function:

$$ g(x) = \sum \left( p \times x^a \right) $$

where the sum is taken over all pairs of $(a, p)$.

For example, a regular 6-sided dice would have generating function for its distribution:

$$ \frac 1 6 (x + x^2 + ... + x^6) $$

because the probability of getting each sum from $1$ to $6$ is $\frac 1 6$.

Consider 2 functions $g_1(x)$ and $g_2(x)$ being the g.f. represent the probability when 2 set of dices are rolled. It can be proven that the g.f. of the probability when the two sets of dices are rolled is $g_1(x)\times g_2(x)$. (the proof is quite easy, you should be able to prove this yourself)

Therefore, to calculate the distribution, you can:

  • Make the g.f. for each dice.
  • Multiply them all together. (use FFT or naive polynomial multiplication)
  • Calculate the coefficients.