# Probability of two identical faces when three dice are thrown

I tried to make a web page that mimics throwing $3$ dice. I often get $2$ or all $3$ having the same number. Trying to figure out if the random generator is broken or its normal?

So if I throw similar $3$ dice randomly, how often will two of them have the same number?

I want to test my code, what will be a good sample size? $10,000$ trials? Each is $1$-$6$. Samples of code here: http://sel2in.com/pages/prog/html/dice

• You might look up the famous "Birthday Problem." It is mathematically the same as your question and the probabilities are even more surprising due to larger numbers. – Ned Oct 30 '17 at 12:44

Probability of getting $3$ same outcome is $\frac{6}{6^3}=\frac{6}{216}=\frac1{36}$.

Probability of getting all different outcome is $\frac{6}{6}\frac{5}{6}\frac{4}{6}=\frac{20}{36}$.

Probability of getting a pair of same outcome would be $1-$ the two quantity above.

$$1-\frac{1}{36}-\frac{20}{36}=\frac{15}{36}$$

• thanks, that explains it, quite a lot. – tgkprog Oct 29 '17 at 21:44
• Any way to know what would be a good sample size? How many throws would i have to collect data to test this sufficiently? 36 would be minimum i guess? or 1,000 ? – tgkprog Oct 29 '17 at 21:46
• I would certainly prefer larger number compared to $36$. I think it should be easy to generate your answer and record the count of each of the three cases. try Chi-square test? – Siong Thye Goh Oct 29 '17 at 21:50
• Yes can make a test suite. Will read up on Chi-squared test – tgkprog Oct 31 '17 at 7:52

It may be helpful to note that the event of interest can be modeled using a discrete random variable $X$: $X = i$ if $i$ of three dices result in the same number, $i = 0, 2, 3$. You are interested in determining $P[X = 2]$ (or perhaps $P[X = 2] + P[X = 3]$).

Taking $P[X = 2]$ for example, it can be computed as follows: \begin{align} P[X = 2] = \frac{\binom{3}{2}\times\binom{6}{1}\times\binom{5}{1}}{6^3} = \frac{15}{36}. \end{align}

The logic goes like this: imagine you are allocating three distinguishable balls into $6$ boxes labeled from $1$ to $6$. Without restriction, there are $6^3$ ways to do so. If it is required that exactly $2$ of three balls are allocated in the same box (hence the remaining ball must be put in another box), you can first determine which two balls will be allocated to the same box ($\binom{3}{2}$ ways), then you are free to choose which one they go ($\binom{6}{1}$ ways), finally, the third ball can go to any one of the remaining $5$ boxes.

In this way, you may enumerate the whole distribution of $X$.

• I +1 yesterday you without understanding your answer. Get it now, I think, you turned it around. So the boxes are the dice number and the balls represent the dice. Need to give that one line 101 explanation for us slow ones :) – tgkprog Oct 31 '17 at 7:54