How Random Number Generation Works
A random number generator (RNG) produces a sequence of numbers that lack any predictable pattern. Computer-based RNGs use mathematical algorithms that take a starting value (seed) and produce a deterministic sequence that appears random. These are called pseudorandom number generators (PRNGs).
To generate a random integer between a minimum and maximum value, the formula is:
Random Integer = floor(random() × (max − min + 1)) + min
random() produces a value from 0 (inclusive) to 1 (exclusive). Multiplying by the range size and flooring gives a uniform integer distribution.
Coach Rivera uses the random number generator to assign drill partners at Pinewood Falls High. With 24 players on the roster, he generates numbers 1-24 without duplicates, then pairs them off sequentially. The first two numbers form pair 1, the next two form pair 2, and so on. This eliminates any bias in partner selection and keeps practice competitive.
Pseudorandom vs. True Random
There is an important distinction between pseudorandom and true random number generators. Understanding when each is appropriate prevents misuse.
| Feature | Pseudorandom (PRNG) | True Random (TRNG) |
|---|---|---|
| Source | Mathematical algorithm | Physical phenomenon (atmospheric noise, radioactive decay) |
| Deterministic | Yes (same seed = same sequence) | No |
| Speed | Very fast | Slower (depends on entropy source) |
| Use cases | Games, simulations, sampling, statistics | Cryptography, lotteries, security keys |
| Example | Math.random(), Mersenne Twister | random.org, hardware RNG chips |
For passwords and encryption, use the Web Crypto API (crypto.getRandomValues) which accesses the operating system's cryptographic RNG. Our password generator uses this approach.
Dice Probability Reference
When rolling multiple dice, the probability of each sum depends on how many combinations produce that total. The table below shows the probability distribution for 2d6 (two six-sided dice), the most common dice roll in board games.
| Sum | Combinations | Probability | Sum | Combinations | Probability |
|---|---|---|---|---|---|
| 2 | 1 | 2.78% | 8 | 5 | 13.89% |
| 3 | 2 | 5.56% | 9 | 4 | 11.11% |
| 4 | 3 | 8.33% | 10 | 3 | 8.33% |
| 5 | 4 | 11.11% | 11 | 2 | 5.56% |
| 6 | 5 | 13.89% | 12 | 1 | 2.78% |
| 7 | 6 | 16.67% |
Total possible outcomes for 2d6 = 6 × 6 = 36. The sum of 7 has the most combinations (1+6, 2+5, 3+4, 4+3, 5+2, 6+1).
For a single die with n sides, each face has a probability of exactly 1/n. The expected value (average roll) is (n + 1) / 2. For a d6, that's 3.5. For a d20, it's 10.5.
Common Uses for Random Numbers
Random number generation has applications across many fields. The table below shows common use cases and the appropriate generator type for each.
| Use Case | Range / Type | Generator |
|---|---|---|
| Lottery numbers (Powerball) | 5 numbers from 1-69 + 1 from 1-26 | True RNG (official); PRNG (for fun) |
| Raffle drawing | 1-N (no duplicates) | PRNG is fine |
| Board game dice | d6, 2d6 | PRNG is fine |
| D&D ability scores | 4d6 drop lowest, ×6 | PRNG is fine |
| Statistical sampling | Row numbers from dataset | PRNG is fine |
| A/B test assignment | 0 or 1 (50/50) | PRNG is fine |
| Password generation | Characters from set | Cryptographic RNG required |
| Encryption keys | Large integers | Cryptographic RNG required |
PRNG = pseudorandom number generator (this tool). Cryptographic RNG = crypto.getRandomValues() or hardware entropy source.
Tom, Pinewood Falls' retired engineer, uses the random number generator to pick which house projects to tackle each weekend. He numbers his project list 1 through 12 and lets the generator decide. "Takes the decision fatigue out of it," he says. He uses the percentage calculator to track what fraction of his project list he has completed.
The Law of Large Numbers
The law of large numbers states that as the number of trials increases, the average of the results approaches the expected value. For a fair coin, the proportion of heads approaches 50% as you flip more and more times. However, this does not mean that short-term deviations are "corrected." It means they become proportionally insignificant.
After 10 flips, getting 7 heads (70%) is common. After 1,000 flips, getting 700 heads (70%) is extremely unlikely. The absolute deviation might grow (say, 520 heads vs. 500 expected), but the percentage deviation shrinks (52% vs. 50%). This is why casinos are profitable: the longer you play, the more closely the results match the house edge.
Maya uses the coin flip tool to settle disputes with her study group at Pinewood Falls High. She once flipped 100 coins to demonstrate the law of large numbers for a statistics project. The result was 47 heads and 53 tails, close to the expected 50/50 split. Her teacher, impressed, suggested she use the test grade calculator to see what score she needed on the final to keep her A.
This generator uses JavaScript's Math.random() pseudorandom number generator. It is suitable for games, educational exercises, casual sampling, and entertainment. Do not use it for cryptographic purposes, official lottery drawings, or security-critical applications.