Probability facts for 1–40
| Question | Answer |
|---|---|
| Chance of one specific number | 1 in 40 (2.50%) |
| Chance of an even number | 20 of 40 = 50% |
| Chance of a prime number | 12 primes = 30% |
| Average result (expected value) | 20.5 |
| Standard deviation | 11.54 |
| Chance a given number shows up at least once in 10 picks | 22.4% |
| Chance of at least one repeat in 5 picks | 22.9% |
| Picks needed for a 50% chance of a repeat | 8 |
| Average picks to see every number at least once | 171 |
How it works
The generator draws a uniform random integer from 0 to 39 with crypto.getRandomValues and adds 1. Rejection sampling removes the small bias that the plain “random modulo 40” trick would cause (here 232 mod 40 = 16 values would otherwise be favored).
The repeat surprise
Duplicates come sooner than intuition suggests. With 40 possible values, 8 picks already give a better-than-even chance that two match — the same maths as the birthday problem. Tick “No repeats” if you need distinct numbers.