[Math] the probability of rolling X specific numbers on Y six-sided dice

binomial distributiondiceprobability

I am writing the AI for a dice game and I have hit a mental block.

I need to know the probability of rolling $X$ specific numbers on Y six-sided dice, where $Y \leq 6$ and $X < Y$ (otherwise the probability would obviously be 0!)

E.g. What is the probability of rolling a 2 and a 4 with 5 dice.

I know that the number of total rolls is $6^Y$ so the answer must be something like…

$f(x,y)/(6^Y)$

Any suggestions?

Thanks in advance!

Best Answer

If you roll $5$ six-sided dice, there are $5^5$ ways not to roll a two, $5^5$ ways not to roll a four, and $4^5$ ways to roll neither a two nor a four. By inclusion-exclusion, the number of obtaining at least one two and at least one four when rolling $5$ dice is

$$6^5-5^5-5^5+4^5$$

Related Question