I found this really useful formula from the dice article on mathworld.
Here is my version in Python.
def P(p, n, s): """ Taken from: http://mathworld.wolfram.com/Dice.html :param p: sum of rolls :param n: num rolls :param s: num sides :return: The probability of summing to p with n rolls of an s-sided die >>> P(7, 2, 6) 0.16666666666666666 """ return 1 / s ** n * sum([(-1) ** k * ncr(n, k) * ncr(p - s * k - 1, n - 1) for k in range(0, int((p - n) / s) + 1)])
The domain of my problem will be restricted to this
1 <= p <= 40,
1 <= n <= 10
1 <= p <= 60,
1 <= n <= 10
However, in the game I'm using this algorithm for, there is a special rule for if I roll a 1. The rule is that you score a 0 if there is a 1 in any of the rolls. For example, if you roll
1, 5, 6, your sum is 0, not 12.
How do I exclude any roll containing a 1? I'm very new to probability and statistics, so I thought I could just multiply the answer by the probability of not rolling a 1, but I don't know if this is correct.
For example, if my probability is
H(p,n,s), it should be:
H(p, n, s) = P(p, n, s) * ((s - 1)/ s) ** n
(5 / 6) ** n is the probability of not rolling a 1 n times in a row.
TL;DR: How do I get the probability of summing to p with n rolls an s-sided die excluding any sum that includes a roll of 1.