Connect a formula to observable experiments
A placement aptitude test contains ten independent true/false questions. If a student guesses randomly, what is the probability of exactly seven correct answers? We can calculate the answer using the binomial distribution and also estimate it by simulating many ten-question attempts.
The two answers serve different purposes. Theory describes the model exactly. Simulation demonstrates long-run frequency, helps test implementation and supports cases where an exact formula may later be unavailable.
Model
Define trials, success probability and independence.
Calculate
Find exact and at-least probabilities.
Experiment
Simulate repeatedly with a reproducible seed.
Four conditions must hold
- A fixed number n of trials occurs in every experiment.
- Each trial has two modeled outcomes: success or failure.
- The success probability p remains constant.
- Trials are independent under the model.
Let X be the number of successes. Then X can take integer values 0 through n. Its expected value is E[X]=np and variance is np(1−p).
| Input | Allowed values | Meaning |
|---|---|---|
| n | Positive integer | Trials per experiment |
| p | 0 ≤ p ≤ 1 | Success chance per trial |
| k | 0 ≤ k ≤ n | Target successes |
| M | Positive integer | Repeated experiments |
Choose positions, then assign outcomes
P(X=k) = C(n,k) × p^k × (1−p)^(n−k)
C(n,k) counts which k of the n positions are successes. Every particular arrangement has probability p^k(1−p)^(n−k). Multiplication combines independent outcomes; multiplication by the combination count covers all arrangements with exactly k successes.
At least k successes
P(X≥k) = Σ from j=k to n of P(X=j)
“Exactly seven” and “at least seven” are not interchangeable. At least seven includes 7, 8, 9 and 10. For thresholds near zero, a complementary calculation 1−P(X<k) may require fewer terms.
Turn probability into repeated Boolean trials
- Generate a uniform pseudo-random number u in [0,1).
- Count success when u<p.
- Repeat n times to obtain one value of X.
- Record whether X=k and whether X≥k.
- Repeat the complete experiment M times.
- Estimate probability as matching count divided by M.
estimated P(X=k) = number of experiments with k successes / M
A pseudo-random generator is deterministic. A seed selects its starting state. Using the same program, inputs and seed gives the same simulation, which is essential for debugging and teaching. Changing the seed provides another valid sample.
Exactly seven correct guesses out of ten
For random guessing on independent true/false questions, n=10, p=0.5 and k=7.
C(10,7)=120.0.5^7 × 0.5^3 = 0.5^10 = 1/1024.P(X=7)=120/1024=0.1171875.P(X≥7)=[C(10,7)+C(10,8)+C(10,9)+C(10,10)]/1024.- The numerator is
120+45+10+1=176, so the result is0.171875.
A run of 10,000 experiments might produce 0.119 or 0.115 for exactly seven. That difference is expected sampling variation, not automatic evidence that the formula or code is wrong.
Complete Python implementation
The program accepts a general binomial experiment, calculates exact probabilities, runs a reproducible simulation and compares both exact-k and at-least-k events. It also checks the simulated average successes against np.
Loading source…Trace one experiment with n=4 and p=0.5
- Define the experiment.
- Compare first random value.
- Record failure.
- Record second success.
- Finish one experiment.
- Update event counters.
- Begin another experiment.
- Convert counts to relative frequency.
- Evaluate sampling difference.
Press Next to begin.
Start with probabilities that must be exact
p = 0 boundary
p = 1 boundary
Single trial
Distribution sum
Reproducibility
Larger sample comparison
Convergence is a tendency, not equality
By the law of large numbers, relative frequency tends toward the modeled probability as M grows. Typical Monte Carlo error decreases proportionally to 1/√M. To reduce typical error by a factor of ten, we therefore need roughly one hundred times as many experiments.
| Component | Time | Space |
|---|---|---|
| Exact P(X=k) | O(1) high-level operations | O(1) |
| P(X≥k) | O(n−k+1) | O(1) |
| Simulation | O(Mn) | O(1) |
Simulation output is evidence about the code and the assumed process, not proof that real-world trials satisfy independence or constant p. Model validation must come before numerical confidence.
Check theoretical and experimental reasoning
Which values belong to X≥7 when n=10?
About how many times more experiments reduce typical error by 10×?
Extensions
- Display the complete theoretical and simulated distribution for k=0…n.
- Repeat many seeds and summarize the distribution of estimation error.
- Add a confidence interval for the estimated event probability.
- Simulate unequal trial probabilities and explain why the binomial formula no longer applies.
- Build a without-replacement simulation and compare it with a hypergeometric model.
Distinguish model, estimate and observation
Why does C(n,k) appear?
It counts the different choices of k success positions among n trials; each such arrangement has the same probability under constant independent p.
Why does simulation not equal theory?
A finite random sample varies. Theory gives the model probability; simulation gives one relative-frequency estimate.
What does a seed do?
It fixes the starting state of the pseudo-random generator, making an experiment reproducible; it does not make the numbers truly random.
When is binomial inappropriate?
When trial count is not fixed, outcomes are not binary under the model, p changes, or trials are dependent.
Why might more simulations be wasteful?
Error falls only with the square root of M, so very high precision is expensive. If an exact reliable formula exists, simulation may be best used for demonstration or verification.
Probability is a model; simulation is an experiment on that model
The exact binomial result and Monte Carlo estimate should be connected but not confused. Careful work states assumptions, derives the event probability, records the seed and sample size, measures error and resists interpreting random variation as a contradiction.
