# Probability of getting a particular sum from n m-sided dice c#

I am trying to generate a probability of getting a specific number x from n dice, with no guarantee of them having the same number of sides. (eg, 1d6 + 2d10)

Does there exist a mathematical formula for this?

Does there exist a formula for getting above x?

The real trick here is to use generating functions.

The way they work is by assigning the probabilities to a polynomial, with each term having coefficient equal to its probability of being rolled, and power the value of the roll.

Then, one simply looks at the coefficient of the term with power equivalent to the desired sum for the probability.

For example, let's take your situation of 1 fair 6 sided dice and 2 fair ten sided die. The polynomial we write is $$(\frac16x+\frac16x^2+\frac16x^3+\frac16x^4+\frac16x^5+\frac16x^6)\cdot(\frac1{10}x+\frac1{10}x^2+\frac1{10}x^3+\frac1{10}x^4+\frac1{10}x^5+\frac1{10}x^6+\frac1{10}x^7+\frac1{10}x^8+\frac1{10}x^9+\frac1{10}x^{10})^2$$$$\frac1{600}\cdot(x+x^2+x^3+x^4+x^5+x^6)\cdot(x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9+x^{10})^2$$

Let's find the coefficient of $$x^{15}$$. Using Wolfram Alpha, I found the coefficient to be 0.085. This tells us the probability of the sum totalling 15 is $$\color{red}{0.085}$$

The general problem is difficult.

This question shows several ways of going about it, using a relatively tractable example (number of ways three 6-sided dice can sum to $$11$$). Generating functions (as in Rushabh's answer) is one way.

If you're looking to solve the inequality problem, then inclusion-exclusion would probably be your best bet, but that would mean calculating the probability of a number of specific cases.

A spreadsheet makes it easy for a particular set of dice. For your example, leave ten blank rows and make a column from $$1$$ to $$26$$ representing the possible sums. In the second column put a $$1$$ in the rows with $$1$$ through $$6$$ representing the fact that there is $$1$$ way for the first die to total each of those. In the third column we will compute the number of ways to total each number from the first two dice. Each cell should be the sum of the numbers in the second column from one to ten rows above because each of those rows can contribute to the sum. The third column is just like the second. Now total the third column to get the total number of rolls, which should be $$6\cdot 10\cdot 10=600$$. The chance of each sum is the number on that line divided by the total number of rolls. As a check I get the chance of $$14$$ or $$15$$ to be $$\frac {51}{600}$$

This is explicitly calculating the generating function.