Understanding the hypergeometric distribution calculator — concept and principle
The hypergeometric distribution gives the probability of drawing exactly k "successes" when you take n items without replacement from a population of N items that contains K successes. It is the right model for card games (aces in a poker hand), lotteries (matching numbers), quality sampling from a lot (defective units in a sample) and any draw where each item can be picked only once. The calculator returns P(X = k) and the chance of drawing at least one success.
How it is calculated
- P(X = k) = C(K, k)·C(N − K, n − k) ÷ C(N, n)
- P(X ≥ 1) = 1 − C(N − K, n) ÷ C(N, n)
C(a, b) = a! ÷ (b!(a − b)!) is the number of ways to choose b items from a. k must satisfy max(0, n − (N − K)) ≤ k ≤ min(n, K). The mean is n·K/N.
The principle
Every set of n items is equally likely, and there are C(N, n) such sets. A favourable set picks k of the K successes, in C(K, k) ways, and fills the remaining n − k places from the N − K failures, in C(N − K, n − k) ways. Favourable divided by total gives the probability. Unlike the binomial, the chance of a success changes after each draw because the population shrinks; when N is much larger than n, the two distributions become nearly the same.
Worked example
- Defaults: a 52-card deck (N = 52) with 4 aces (K = 4), a 5-card hand (n = 5), exactly 1 ace (k = 1).
- C(4, 1) = 4 and C(48, 4) = 194,580, so favourable hands = 778,320.
- All hands: C(52, 5) = 2,598,960.
- P(X = 1) = 778,320 ÷ 2,598,960 ≈ 0.2994736356.
- No ace: C(48, 5) = 1,712,304, so P(X ≥ 1) = 1 − 1,712,304 ÷ 2,598,960 ≈ 0.3411580017.
| Successes in population K | P(X = k) |
|---|---|
| 1 | 0.0961538462 |
| 2 | 0.177224736 |
| 3 | 0.2445701357 |
| 4 | 0.2994736356 |
| 5 | 0.3431468741 |
| 6 | 0.3767314618 |
| 8 | 0.4178625296 |
How to read the result
About 30% of five-card hands contain exactly one ace and about 34% contain at least one. The mean is 5 × 4/52 ≈ 0.385 aces per hand. For a 6/45 lottery (N = 45, K = 6, n = 6) the chance of matching all six is 1 ÷ C(45, 6) = 1 in 8,145,060, and matching exactly three is about 2.24%.
Common mistakes
- Using the binomial for small populations; drawing without replacement changes the odds.
- Swapping K and n: K is the number of successes in the population, n is how many you draw.
- Forgetting that exact-k probabilities must be summed for "at least k" when k is above 1.
Frequently asked questions
What is the probability of exactly 2 aces in 5 cards?
C(4, 2)·C(48, 3) ÷ C(52, 5) = 6 × 17,296 ÷ 2,598,960 ≈ 0.0399.
When can I use the binomial instead?
When the sample is a small fraction of the population (a common rule is n ≤ 5% of N), using p = K/N.
Does the order of the draws matter?
No. The hypergeometric counts unordered selections, so the order in which cards appear does not change the result.
Sources: Sheldon M. Ross, A First Course in Probability, Pearson — hypergeometric random variables · William Feller, An Introduction to Probability Theory and Its Applications, Vol. 1, Wiley — hypergeometric distribution