Target cards in a draw
When you draw cards without putting them back, how many from a chosen group will you see? Simulate it and compare with the exact hypergeometric distribution.
Simulation settings
The simulation counts how many of these appear in each draw.
Whole number from 1 to 52.
The same seed and settings always reproduce exactly the same results.
The mathematics
If K of the 52 cards are targets and n cards are drawn, the number of targets X has the hypergeometric distribution:
P(X = k) = C(K, k) × C(52 − K, n − k) / C(52, n) E[X] = n·K / 52 Var[X] = n·(K/52)·(1 − K/52)·(52 − n)/51The last factor, (52 − n)/51, is the finite population correction. It makes the variance smaller than it would be if each card were returned and reshuffled, because drawing without replacement removes uncertainty as the deck shrinks. Compare your result with the exact numbers on the calculator.
Things to try
- Use hearts as the target with 5 cards per draw. The exact mean is 5 × 13 / 52 = 1.25; compare the simulated mean at 100 and at 100,000 draws.
- Set the target to “King of spades” and draw 26 cards. The probability should be exactly 50%. Why? (Half the deck is drawn and each card is equally likely to be in that half.)
- Draw all 52 cards: the variance falls to 0 because every draw is identical in how many targets it holds.