Today I needed to write a function that would select a random set of N=5 items, containing at most one special item, from a set of R=24 regular and S=4 special items.
-
Today I needed to write a function that would select a random set of N=5 items, containing at most one special item, from a set of R=24 regular and S=4 special items.
I calculated that the number of sets with no special items is \( \binom{R}{N} =\binom{24}{5} = 42504 \).
And I calculated that the number of sets with one special item is \( \binom{R}{N-1} \cdot S = \binom{24}{4} · 4 = 42504 \) — the same, so the probability of getting a set with one special item is exactly ½.
Then I spent a lot of time trying to figure out where my mistake was. Surely not a bug in my venerable binomial-coefficient-computing program?
No, they are equal, and it is a pure coincidence, an effect of the fact that \( R-N+1 = N\cdot S\).
If any of the three numbers had been different, the two groups would have been different sizes.
-
Today I needed to write a function that would select a random set of N=5 items, containing at most one special item, from a set of R=24 regular and S=4 special items.
I calculated that the number of sets with no special items is \( \binom{R}{N} =\binom{24}{5} = 42504 \).
And I calculated that the number of sets with one special item is \( \binom{R}{N-1} \cdot S = \binom{24}{4} · 4 = 42504 \) — the same, so the probability of getting a set with one special item is exactly ½.
Then I spent a lot of time trying to figure out where my mistake was. Surely not a bug in my venerable binomial-coefficient-computing program?
No, they are equal, and it is a pure coincidence, an effect of the fact that \( R-N+1 = N\cdot S\).
If any of the three numbers had been different, the two groups would have been different sizes.
This reminds me of the time that Reddit's `r/programmingCircleJerk` described one of my blog posts as “Haskaller too smart to get anything done”.