Random Number Generator
Generate random numbers in any range with cryptographically secure randomness. Choose how many numbers, allow or block duplicates, and sort the results.
Quick Examples
What Is a Random Number Generator?
A random number generator (RNG) selects numbers from a defined range with no predictable pattern. Every number in the range has exactly the same chance of being picked on every draw, and each draw is independent of the ones before it — like drawing a numbered ball from a bag without looking, then putting it back.
Randomizers are everywhere: raffles and giveaways, lottery draws, dice and board games, shuffling playlists, assigning experiment groups, and sampling data for statistics. This page explains how the generator above works, what makes its output trustworthy, and how to use it for dice, coins, lotteries, and draws.
How This Generator Works
Enter a minimum and maximum (both inclusive), choose how many numbers to generate (up to 1,000 at a time), and optionally tick no duplicates or choose a sort order. The numbers are drawn with the Web Crypto API's crypto.getRandomValues(), which pulls from your operating system's cryptographically secure entropy pool rather than a simple arithmetic pseudo-random sequence.
Rejection sampling against modulo bias: naively taking a random 32-bit integer modulo the range size makes some outcomes slightly more likely, because 2³² = 4,294,967,296 is rarely an exact multiple of the range — for a range of 100 it leaves a remainder of 96. This generator discards values in that uneven remainder region before applying the modulo, restoring an exactly uniform distribution.
True Randomness vs. Pseudo-Randomness
Not all "random" is equal. Three tiers of random sources are worth knowing:
| Source | How It Works | Trust Level | Typical Use |
|---|---|---|---|
| Math.random() | Pseudo-random, seeded by the browser engine | Not for anything where prediction matters | Games, animations, shuffling a playlist |
| crypto.getRandomValues() (used here) | Cryptographically secure, seeded from OS entropy | Suitable for draws, raffles, tokens | Anything fair or security-sensitive |
| Hardware generator | Samples physical noise (thermal, atmospheric) directly | Highest assurance | Cryptographic key generation, gambling machines |
A pseudo-random generator like Math.random() is deterministic: knowing the seed reproduces the whole sequence — useful for simulations, unacceptable for security. Cryptographically secure generators are designed so that past output reveals nothing about future output.
Uniform Distribution and Independent Draws
Every value in the range is equally likely: with a range of 1 to 10, each number has a 1-in-10 chance (10%) on every draw. Getting a 7 once does not make 7 more or less likely next time — each draw is independent — the defining property of a fair draw, and the one people most often misunderstand.
Common Ranges and the Chance of Any One Value
| Use | Range | Chance of a Given Value |
|---|---|---|
| Coin flip | 0 to 1 | 50% |
| Six-sided die | 1 to 6 | 16.67% |
| Twenty-sided die | 1 to 20 | 5% |
| Percentile | 1 to 100 | 1% |
| Lottery ball, 1 of 49 | 1 to 49 | 2.04% |
| Raffle with 500 tickets | 1 to 500 | 0.2% |
With vs. Without Duplicates
With repeats allowed, each draw is independent — the same number can appear more than once, exactly like rolling a die repeatedly. Use this for simulating independent trials.
With no duplicates, each drawn number is set aside and cannot be drawn again — like keeping the ball out of the bag. The result is a random sample without replacement, which is what raffles, lottery draws, and team drafts need. This mode requires the range to contain at least as many values as the count you request.
Simulating Dice and Coins Correctly
A coin is a range of 0 to 1; a six-sided die is 1 to 6; a twenty-sided die is 1 to 20. But two dice are not uniform: one die gives every face the same chance, while the sum of two dice does not, because there are more ways to make a 7 than a 2.
| Total | Ways (of 36) | Probability |
|---|---|---|
| 2 | 1 | 2.78% |
| 3 | 2 | 5.56% |
| 4 | 3 | 8.33% |
| 5 | 4 | 11.11% |
| 6 | 5 | 13.89% |
| 7 | 6 | 16.67% |
| 8 | 5 | 13.89% |
| 9 | 4 | 11.11% |
| 10 | 3 | 8.33% |
| 11 | 2 | 5.56% |
| 12 | 1 | 2.78% |
To simulate two dice, generate two numbers from 1 to 6 and add them — never a single number from 2 to 12, which would wrongly give every total the same 1-in-11 chance.
Lottery Numbers and Odds
For a lottery-style draw, set the range to the ball pool, the count to the number of picks, enable no duplicates, and sort ascending — the "Lottery 6 of 49" quick example does exactly this. Choosing 6 numbers from 1 to 49 can be done 13,983,816 ways, so one ticket's jackpot chance is 1 in 13,983,816. Random picks cannot predict draws or improve the odds, but they do guarantee a ticket free of human pattern bias.
Real-World Uses
- Raffles and giveaways: pick winners fairly from numbered entries with no duplicates.
- Games: roll dice, flip coins, or seed procedural content.
- Statistical sampling: draw unbiased random samples from a numbered population.
- Experiment design: randomly assign participants to A/B test groups.
- Classroom demos: illustrate probability and sampling variation live.
A note on passwords: the randomness quality here is fine, but passwords need letters, symbols, and guaranteed character-class coverage, which a number generator cannot provide. Use a dedicated password generator for credentials.
A Brief History of Random Number Generation
Humanity has randomized outcomes for millennia. Archaeologists have unearthed early dice crafted from sticks, shells, and bones; the oldest known six-sided cubic dice trace back to the Indus Valley around 2500 B.C.
The digital age began in 1947, when the RAND Corporation built an electronic generator linking a roulette mechanism to a computer. In 1949, John von Neumann proposed the middle-square method, but its sequences inevitably collapsed into short repeating cycles. In 1956, ERNIE began drawing Britain's Premium Bond lottery numbers, and in 2012 Intel's RDRAND/RDSEED instructions brought hardware-grade randomness to mainstream processors.
Common Mistakes
- The gambler's fallacy. After five coin-flip heads in a row, tails is still exactly 50%. Randomness has no memory.
- Using Math.random() for security. It is deterministic and predictable — fine for games, never for tokens or secrets.
- Hand-rolled modulo without rejection sampling. Taking a random integer modulo the range size biases results toward lower values whenever the range does not divide the integer space evenly.
- Simulating two dice with one 2–12 draw. Real dice totals follow a triangular distribution peaking at 7, not a flat one.
- Expecting small samples to look "even". True randomness clusters: a run of 4 heads in 20 flips is normal, not evidence of bias. Evenness emerges only over large samples.
Frequently Asked Questions
Conclusion
A good random number generator draws from a cryptographically secure source, gives every value an exactly equal chance (no modulo bias), and offers the controls real tasks need: count, uniqueness, and sorting. The traps are statistical, not technical — independent draws have no memory, and combined outcomes like two dice are not flat.
Use the random number generator above for raffles, dice, lotteries, and sampling — with crypto-grade randomness generated in your browser.