Question:Throw at random 10 balls into 4 boxes. What is the probability that exactly 2 boxes remain empty?
My Solution: Using the stars and bars method, the boxes and balls can be thought as $0$ and | e.g. one configuration would be
$$
000000|00|0|0
$$
which would represent 6 balls in the first box etc. Thus the total number of configurations would be $\binom{13}{3}=286.$
There are $\binom{4}{2}$ to have 2 out of the 4 boxes empty, then to ensure the balls are put into only the other two boxes you place 1 ball into the other two boxes and then distribute the remaining 8 balls into the 2 boxes, which, using the same method as above, gives $\binom{9}{1}$ ways. Therefore there are $\binom{4}{2}*\binom{9}{1}=54$ ways of having exactly two boxes empty, giving a probability of $54/286\approx0.189.$
I did a simulation in MATLAB to confirm the answer, to find that I get a probability of $\approx0.005$, way off my answer. I can't see why my code and my solution above disagree so I'll post my code Here
Best Answer
Temporarily assume the balls are labelled. This allows us to look at the sample space $\{1,2,3,4\}^{10}$ of size $4^{10}$ which will happen to be equiprobable, allowing us to use counting methods. (the sample space of size $\binom{13}{3}=286$ where the balls are indistinct is not equiprobable and so we may not use elementary counting methods with this choice)
Break apart via multiplication principle.
Applying multiplication principle then, there are $\binom{4}{2}(2^{10}-2)=6132$ ways to arrange the ten balls among the four boxes having exactly two boxes empty.
Dividing by the size of the sample space then, the probability is:
$$\frac{6132}{4^{10}}\approx 0.0058479$$
much more closely matching your simulation.