Random Number Generator
Generate truly random numbers within any range you specify. Perfect for raffles, games, statistical sampling, passwords, and decision making.
As an Amazon Associate and CJ Affiliate publisher we earn from qualifying purchases. Prices and availability may vary.
Random Numbers Guide
What's the difference between True and Pseudo-Random?
Computer-generated random numbers are technically 'pseudo-random' — they use deterministic algorithms seeded by values like the current time. For almost all practical purposes (games, raffles, statistical sampling, passwords), this is indistinguishable from true randomness. True hardware random number generators use physical processes (radioactive decay, electronic noise) as entropy sources. Web browsers' Math.random() function is cryptographically sufficient for most purposes but should not be used for genuinely high-security cryptographic applications, which instead rely on dedicated cryptographically secure random number generators.
What should I know about Raffle and Draw Uses?
For a raffle with 100 tickets, generate a random integer between 1 and 100. For multi-winner draws, use 'unique' mode to generate multiple non-repeating numbers. For team selection from a list of 20 people, generate numbers 1–20 without repeats and assign names to positions. For a coin flip: 1 = heads, 2 = tails (generate 1 or 2). For a dice roll: 1–6. For two dice: generate two numbers 1–6 separately.
What should I know about Statistical Sampling?
Random sampling is fundamental to statistics — selecting a representative subset without bias. To randomly sample 10 items from a list of 50: generate 10 unique numbers between 1 and 50, then select those items. Stratified random sampling divides the population into groups (strata) and samples randomly within each group — ensuring representation of all subgroups. This is how opinion polls, clinical trials, and quality control sampling are designed.
What do I need to know about Random Numbers in Everyday Life?
Random number generation underpins: lottery draws (certified hardware RNG), gambling (casino games use hardware RNG for fairness certification), cryptography (encryption keys require high-entropy randomness), computer games (procedural generation of levels, enemies, loot), scientific simulations (Monte Carlo methods), and A/B testing (random assignment of users to test groups). The quality of randomness matters enormously in security contexts — weak randomness in key generation has caused catastrophic, real-world security failures in the past.
What should I know about How Pseudo-Random Number Generators Work?
Most computer-generated 'random' numbers are actually pseudo-random: produced by a deterministic mathematical algorithm that starts from an initial value called a seed and then applies a formula repeatedly to generate a long sequence of numbers that pass statistical tests for randomness, even though the entire sequence is technically predictable if you know the seed and algorithm. Common algorithms include the linear congruential generator (a simple, fast formula using multiplication, addition, and modulo) and the Mersenne Twister (used by default in many programming languages, prized for an extremely long repeat cycle of 2^19937 − 1 numbers before the sequence repeats). The seed is often drawn from something that varies constantly, like the computer's current clock time in milliseconds, so that two separate runs produce different-looking sequences in practice. For applications where true unpredictability matters — cryptographic keys, security tokens, lottery draws — a cryptographically secure pseudo-random number generator (CSPRNG) is used instead, designed so that even knowing part of the output sequence gives no practical way to predict the rest.
What's the key thing to understand about Random Number Distributions?
Not all random numbers are generated with equal likelihood across their range. A uniform distribution, the type most general-purpose random number generators produce by default, gives every value within the specified minimum and maximum an equal chance of being selected — rolling a fair six-sided die is a real-world uniform distribution, where each face has exactly a 1-in-6 chance. A normal (Gaussian) distribution instead clusters values around a central mean, with values becoming progressively less likely the further they fall from that centre, producing the familiar bell-curve shape — human heights and measurement errors tend to follow this pattern naturally. The choice of distribution matters for simulations and statistical sampling: using a uniform generator when a process is naturally normally distributed (or vice versa) will produce a sample that doesn't represent the real-world phenomenon being modelled. A basic random number generator like this one typically produces uniformly distributed values, which is appropriate for lotteries, draws, and unbiased selection, but a different technique (such as the Box-Muller transform) is needed to generate normally distributed random values.
What do I need to know about Seeding a Random Number Generator?
A pseudo-random number generator (PRNG) produces its entire sequence of "random" numbers from a starting value called a seed, using a deterministic formula — meaning the exact same seed will always reproduce the exact same sequence of numbers. This is deliberately useful for debugging and scientific reproducibility: a simulation that behaves unexpectedly can be re-run with the same seed to reproduce the exact same results for inspection, and research that relies on random sampling can report its seed so other researchers can verify the analysis exactly. When no seed is specified, most systems default to seeding from something that changes constantly and unpredictably, like the system clock down to the millisecond, so that successive runs produce different sequences in ordinary use. This is also why PRNGs used for anything security-sensitive (passwords, encryption keys) require a cryptographically secure random source instead — a predictable seed, or a weak seeding method, can make an otherwise "random-looking" sequence guessable.
Worked Example: Probability of a Repeated Draw
If a random number generator picks an integer uniformly between 1 and 100, what's the probability that two independent draws produce the same number? Each draw is independent, and the second draw must match whatever the first draw produced: P(match) = 1/100 = 0.01, or 1%. For three draws, the probability that ALL three match is (1/100)² = 1/10,000 = 0.01%, since the second must match the first (prob 1/100) and the third must also match (another 1/100). This connects to the 'birthday problem' logic used in computer science: even with a huge range (say 1 to 1,000,000), collisions become surprisingly likely once enough numbers are drawn, which is why systems needing guaranteed-unique random IDs use ranges far larger than the expected number of draws, or check explicitly for duplicates rather than relying on randomness alone.
Mean and Variance of a Uniform Random Range
For a random number generator producing integers uniformly from 1 to n, the theoretical mean is (1+n)/2 and the variance is (n²-1)/12. For a standard six-sided die (n = 6): mean = (1+6)/2 = 3.5 (notice this isn't a number the die can actually show — it's the long-run average), and variance = (36-1)/12 = 35/12 ≈ 2.917, giving a standard deviation of √2.917 ≈ 1.708. These formulas let you predict, before ever running the generator, what a large number of draws should average out to and how spread out individual results will typically be — a practical use is checking whether an actual random number generator is behaving as expected: if 10,000 simulated die rolls produce a sample mean far from 3.5 or a sample standard deviation far from 1.708, that's a warning sign of a biased or broken generator, rather than just normal statistical noise.
Reproducibility: Why Seeding Matters
A pseudo-random number generator (PRNG) produces a deterministic sequence of numbers that only looks random — given the same starting 'seed' value, it produces the exact same sequence every single time. This is deliberately useful in software testing and scientific simulations, where reproducibility (being able to re-run an experiment and get identical results) matters more than true unpredictability — fixing the seed lets a researcher share their exact random sequence with a colleague for verification. For applications where genuine unpredictability matters instead (cryptographic keys, lottery draws, security tokens), seeding from a predictable source like the system clock is a known weakness, which is why cryptographically secure random number generators draw their seed from hardware entropy sources (tiny fluctuations in electronic noise, timing jitter) that an attacker cannot predict or reproduce.
Worked Example: Probability of a Specific Outcome in a Range
Using a generator that produces integers uniformly between 1 and 50, what's the probability of getting a number divisible by 5? The divisible-by-5 numbers in that range are 5, 10, 15, ..., 50 — exactly 10 values (50/5 = 10). So P = 10/50 = 0.20, or 20%. This is simply the count of favourable outcomes divided by the total number of equally likely outcomes, the same basic probability principle used throughout random-number applications, from lottery odds to simple dice games, whenever every value in the range is equally likely to be generated.