[Math] Any way to calculate chances of getting “n” hits when rolling “x” die (hit is when I roll more than “y”)

diceprobability

First, let me preface – I saw similar questions already, but to be honest, I didn't understand the answers, or couldn't understand how to convert the answer for given question to my problem.

My problem is:

I have "x", fair, 6-sided die (let's say 3 die)

I count "hit" when at least specific number will be rolled (for example, hit might be from 4, giving 50% chance from single dice, or it can be from 3, giving 66% change).

I need to calculate probability of hitting at least given number of times.

For example: assuming I have 3 die, hit counts from 5 (so 1/3 chance of hitting with each die), I have:

  • 70.3% chance of hitting at least once
  • 25.9% chance of hitting at least twice
  • 3.7% chance of hitting three times

For small number of die, I can simply count by generating all possible sets of results in some program, and then get the hit counts, but with 10 die there are over 60 million possible combinations, and it doesn't look sensible to generate all these sets, just to count how many of them "work".

Is there any simple equation I could use in my program to get the percentages?

Please note that I am not, by far, a mathematician, so my understanding of formulas might be lower than you're generally accustomed to, please dumb-down your answer 🙂

Best Answer

If you have several dice, and you want to know what chance you have of getting a specific formula, then the solution is P = (h+m)^n, where h is the chance of hits, m is the chances of missing, and n is the number of dice involved.

This expands out to a polynomial, eg for 3, h³ + 3h²m + 3hm² + m³.

So if your chance of hitting is say 2 (ie 5, 6), and your miss is 4, (ie 1,2,3,4), this comes out to

8 tri-hits, 3*4*4 = 48 bi-hits, 3*2*16 = 96 hits and 4*4*4 = 64 misses. The sum of these numnbers ought be 216 tosses.

You use the row of the pascal triangle, along with powers of the hit/miss ratio, as

  8   7   6   5    4    3    2     1      0   hits out of 8

  1   8  28  56   70   56   28     8      1   ie  n! / h! m!
256 128  64  32   16    8    4     2      1   hits   ie  2^h
  1   4  16  64  256 1024 4096 16384  65536   misses ie  4^m

n! means 1 * 2 * 3 * 4 * 5 * ... n! It is the factorial.

The first line counts all the different ways of arranging say two hits and six misses (at any probability), ie hmmmhmmm and hmhmmmm are both counted.

The second line counts the possible ways of getting 6 hits, eg 5,6,5,5,6,5 six hits. There are 64 ways of doing this.

The third line counts the possible ways of getting misses, so 2,2,4,3,1 is a way of getting 5 misses.

The total of the row is (H+M)^n, the total possible throws over all the dice. In the present case, H=2, M=4, and H+M=6 possible values, so you have 6^8 = 1679616 possible throws.

The number of 4 hits from 8 die is then 70*16*256/1679616 = 0.170705685

This formula can be implemented in code to handle a large number of throws.

Related Question