AI assistance: An AI agent ran the experiments and helped draft this article.
Imagine a jar with seven chocolate cookies and three plain cookies. You are
packing a box of six. Each time, you pick blindly, so every cookie still in the
jar has the same chance of being selected. Once a cookie goes into the box, it
stays there.
Before working out any probabilities, try to picture a box containing only two
chocolate cookies. The other four would have to be plain.
But the jar only had three plain cookies to begin with.
Oh, that is the catch. This is already impossible, before a probability formula
has entered the picture.
Start with what can actually happen
Use all three plain cookies and there are still three places left in the box.
Those places must contain chocolate cookies. So the smallest possible chocolate
count is six minus three, or three.
The largest possible count is six. There are seven chocolate cookies available,
but the box has only six places.
That leaves just four possible counts: 3, 4, 5 and 6.
An original illustrated sequence of possible and impossible boxes—not a
recorded random draw. C means chocolate; P means plain. The final scene shows
one of the possible four-chocolate boxes. Static storyboard of the starting
jar and the two boundaries.
This is a counting constraint, or a pigeonhole-style argument: there are not
enough plain cookies to fill more than three of the six places. The constraint
comes from what is available, not from how lucky the draw is. Wikipedia's
pigeonhole principle is a
useful introduction to this kind of reasoning.
For a finite count like this, the set of values with nonzero probability is
called the support. Here that set is {3, 4, 5, 6}. The
hypergeometric distribution
describes this sort of count: selecting uniformly from a finite population
without putting the selected objects back.
Okay, now we know what can happen. That still does not tell us which of those
four counts is most likely.
Four possible counts does not mean four equal chances
It is tempting to give 3, 4, 5 and 6 a probability of one quarter each. But those
counts can be made in different numbers of ways.
Treat the ten cookies as ten distinct objects. There are 210 different sets of
six cookies that could go into the box. Under the drawing rule above, those
sets are equally likely.
Here is what exact enumeration of all 210 sets gives:
| Chocolate cookies | Boxes out of 210 | Exact probability | Percentage |
|---|---|---|---|
| 2 | 0 | 0 | 0% |
| 3 | 35 | 1/6 | 16.6667% |
| 4 | 105 | 1/2 | 50% |
| 5 | 63 | 3/10 | 30% |
| 6 | 7 | 1/30 | 3.3333% |
| 7 | 0 | 0 | 0% |
So a box with four chocolate cookies has probability 50%, while six
chocolate cookies has probability about 3.33%. Both are possible; they are
far from equally likely.
The difference becomes easier to see by counting a four-chocolate box. We need
to choose four of the seven chocolate cookies and two of the three plain ones.
C(7, 4) × C(3, 2) = 35 × 3 = 105 boxes
Here C(a, b) means the number of ways to choose b distinct objects from a,
ignoring their order. The total number of six-cookie sets is C(10, 6) = 210.
Dividing gives:
P(four chocolate) = 105 / 210 = 1/2
That is the idea behind the hypergeometric formula. It counts the selections
that fit the requested chocolate count, then divides by all possible selections.
SciPy's hypergeometric documentation
gives the general formula and the bounds used by its implementation.
Putting the cookie back changes the question
Now imagine a slightly different activity. Pick a cookie, record whether it is
chocolate, put it back, and mix the jar before the next pick. Do that six
times. This counts chocolate results in six draws; it does not pack six distinct
cookies into a box. The same physical cookie can appear again.
Every draw now has a chocolate probability of 7/10 = 0.7. Returning the cookie
keeps the jar's composition unchanged, and independent uniform picks give six
independent trials with that fixed probability. That is a
binomial model, written as
Binomial(6, 0.7).
In the original box-packing activity, the next probability depends on what was
already taken:
- After taking a chocolate cookie, 6 of the remaining 9 are chocolate.
- After taking a plain cookie, 7 of the remaining 9 are chocolate.
So the binomial formula is answering a valid question. It is just a different
question from packing six distinct cookies without replacement.
Top: exact counts from all 210 distinct six-cookie boxes. Bottom: exact
Binomial(6, 0.7) arithmetic for six independent draws with replacement. The
shaded counts are impossible in the original packing activity. Both charts use
the saved experiment values; the cookie story changes the explanation, not the
data.
Adding up to one is only one check
The binomial model assigns probabilities of 0.0729%, 1.0206% and 5.9535% to
zero, one and two chocolate results. Together, those add to 7.047%.
Those results can happen when cookies are returned to the jar. They cannot
happen in the original six-cookie box, because there are only three plain
cookies available.
And yet both distributions add up to one. Both also give an expected chocolate
count of 4.2. That is an average over the possible results, not a claim that
a single box contains 4.2 intact cookies.
This is why checking the total and the mean is not enough. A distribution can
pass both checks while representing the wrong process.
The weights on possible outcomes matter too. For four chocolate results, the
binomial model gives 32.4135%; the original without-replacement calculation
gives 50%. Simply knowing that four is possible does not tell us which weight
belongs there.
There is one small distinction worth keeping straight. Probability assigned to
impossible outcomes means the possible outcomes collectively receive too little
mass. It does not, in general, prove that every individual possible outcome has
the wrong weight. In this particular comparison, all four feasible weights do
differ.
Connecting the jar back to the symbols
Once the example makes sense, the general bounds are less intimidating. Using
SciPy's names, let M be the total number of cookies, n the chocolate count in
the jar, and N the number selected. For our jar, M = 10, n = 7, N = 6.
The chocolate count k must be an integer with:
max(0, N - (M - n)) <= k <= min(n, N)
On the left, M - n is the plain-cookie supply. Any places left after using that
supply must be chocolate. The max keeps the lower bound from going below zero.
On the right, the chocolate count cannot exceed either the chocolate supply or
the number of places in the box.
One easy source of confusion: letters vary across references. Wikipedia writes
this same setup with population size N = 10, chocolate supply K = 7, and draw
size n = 6. Match the meanings before substituting the numbers.
What the small experiment checked
This is an illustration of established probability, not a new result. The local
experiment enumerated the 210 sets directly, compared them with a separate
combination calculation, and checked SciPy 1.18.1. The exact fractions sum to one.
It also covered every valid integer marked supply and draw size for populations
of 1–16 objects: 1,784 parameter combinations and 16,164 point-probability
comparisons. The largest difference from exact enumeration was about
3.33e-16, within the predefined absolute tolerance of 1e-12.
Five boundary checks included counts 2, 3, 6, 7 and 3.5. SciPy returned zero for
impossible counts under valid parameters, including the noninteger count 3.5.
Trying to draw eleven cookies from ten is a different problem: the parameters
are invalid, and that check returned NaN.
A first-run check also required exact floating-point equality to one for an
empty draw. SciPy returned 0.9999999999999997. Using the same predefined
tolerance as the other comparisons fixed that check; the exact answer is one.
These are small synthetic cases, not a large-parameter stability study. Six out
of ten is deliberately a large sampling fraction that makes the distinction
visible. This example does not say that a binomial approximation is always
unsuitable; an approximation needs to be judged against the errors its intended
use can tolerate.
The habit to keep is simple: picture how the selection happens, write down what
it permits, and then choose a probability model. The formula should follow the
story.
References for going a little deeper
- Wikipedia: Pigeonhole principle — an introduction to counting constraints.
- Wikipedia: Hypergeometric distribution — finite-population sampling without replacement, its formula and examples.
- Wikipedia: Binomial distribution — independent trials with a fixed probability.
- SciPy: hypergeom and binom — parameter definitions and the implemented probability functions.
- SciPy 1.18.1 source — the version inspected for the numerical comparison.
Follow-up: The cookie jar behind A/B testing: Fisher’s test to churn connects this example to randomized tests, Simpson’s paradox, churn and shared-stock interference.


Top comments (0)