1. The deck model
A standard deck has 52 distinct cards: 13 ranks (A, 2–10, J, Q, K) in each of 4 suits. Each card has an integer id from 0 to 51, id = suit × 13 + (rank − 1). All selections are validated: ids must be integers from 0 to 51, no card may appear twice and the selection size is limited. The interface prevents duplicates and the engine rejects them if they ever arrive.
2. Exact combinatorics
Factorials, permutations P(n, k) = n!/(n−k)! and combinations C(n, k) = n!/(k!(n−k)!) use arbitrary-precision integers (BigInt), so there is no rounding until a final probability is converted to a decimal.
The nine five-card pattern counts come from closed-form counting arguments:
| Pattern | Counting argument | Count |
|---|---|---|
| Straight flush | 10 rank runs × 4 suits | 40 |
| Four of a kind | 13 ranks × 48 other cards | 624 |
| Full house | 13·C(4,3) × 12·C(4,2) | 3,744 |
| Flush | (C(13,5) − 10) × 4 | 5,108 |
| Straight | 10 × (4⁵ − 4) | 10,200 |
| Three of a kind | 13·C(4,3) × C(12,2) × 4² | 54,912 |
| Two pair | C(13,2)·C(4,2)² × 11 × 4 | 123,552 |
| One pair | 13·C(4,2) × C(12,3) × 4³ | 1,098,240 |
| No pattern | (C(13,5) − 10) × (4⁵ − 4) | 1,302,540 |
The ace counts as high or low in a run (A-2-3-4-5 and 10-J-Q-K-A), but runs do not wrap around (Q-K-A-2-3 is not a run). These nine categories partition all 2,598,960 combinations.
3. Random numbers and seeds
Randomness comes from mulberry32, a small, fast, well-tested 32-bit pseudo-random generator. A text seed is hashed to a 32-bit integer with an xmur3-style hash. Each simulator mixes its own name into the seed, so “lab-001” gives different but still reproducible streams in different tools. The same seed, settings and software version always produce identical results.
Cards are drawn with a (partial) Fisher–Yates shuffle, which makes every ordered selection equally likely when the underlying random numbers are uniform. The generator is not cryptographically secure and must not be used for security purposes. A fresh seed is created only when you press “New seed”, using the browser's crypto.getRandomValues where available.
4. Monte Carlo simulation
- Five-card pattern frequencies. For N samples, draw 5 distinct cards, classify the pattern and count. Observed probability = count ÷ N.
- Target cards in a draw. Draw n cards, count how many belong to the chosen target set. Compare the histogram, mean and variance with the hypergeometric distribution.
- Sampling variability. Repeat a whole experiment R times, each with m draws; each yields an estimate of P(at least one target). The spread of the R estimates is compared with
√(p(1−p)/m).
Convergence charts record the running estimate at about 60 log-spaced sample counts. Sample sizes offered are 100, 1,000, 10,000 and 100,000; the engine accepts up to 1,000,000 but the interface limits itself to keep pages responsive.
5. Statistical summaries
- Standard error of a proportion:
√(p(1−p)/n). - 95% intervals use the Wilson score method (z = 1.96), which behaves well for small counts and for probabilities near 0 or 1.
- Coverage is the fraction of intervals that contain the exact value. Roughly 95% is expected; with only nine patterns, seeing one miss is normal.
- Variance in the draws simulator is the unbiased sample variance (denominator n − 1).
6. Verification
The project includes automated unit tests that run on every build. Among other checks they:
- enumerate all 2,598,960 five-card combinations and confirm each pattern count matches the closed-form value exactly;
- confirm hypergeometric probabilities sum to 1 and reproduce the known mean and variance;
- verify seeded generators repeat exactly, differ between seeds and are approximately uniform;
- check that simulation output converges to theory, that spread falls roughly like 1/√n, and that confidence-interval coverage is close to nominal;
- exercise invalid input: duplicate cards, out-of-range ids, oversized draws and impossible parameters.
7. Limitations
- Results are estimates. Any finite simulation has sampling error, which this site displays deliberately.
- A pseudo-random generator is deterministic. It passes statistical checks but is not “truly” random.
- All draws assume a well-shuffled deck of 52 distinct cards with no jokers.
- The lessons are introductory. They are not a substitute for a textbook or a qualified teacher, and nothing here is professional advice of any kind.
8. Reporting errors
If you find a mistake in the mathematics, please tell us through the contact page. Corrections to the counts or formulas should be accompanied by a reference or a short derivation.