1What is a random number generator? (start from zero)
Picture a hat full of numbered ping-pong balls — the kind they use on lottery night. Someone reaches in blind, pulls one out, reads the number, and drops it back in. Do that a hundred times and you've got a hundred random numbers. A random number generator, or RNG, is just the digital version of that hat.
Strip away the tech talk and an RNG does one simple thing: it picks numbers with no pattern and no favorites. If you ask for a number between 1 and 10, each number — 1, 2, 3, all the way to 10 — gets an exactly equal shot. The number it gave you last time has zero influence on what comes next. That's the whole deal, and it's harder to pull off than it sounds.
Why does "no favorites" matter so much? Because the moment some numbers show up more often than others, everything built on top breaks. A raffle where ticket 47 wins twice as often isn't a raffle — it's a rigged game. A password made of "random" letters that secretly favors certain characters is easier to crack. A scientific study that samples "random" patients but keeps picking from the same neighborhood isn't studying the whole population. Fairness is the entire point of randomness, which is why the details in this guide actually matter for real decisions.
Computers, though, have a dirty secret: they're terrible at being random. A computer is a machine that follows instructions exactly — give it the same input and it does the same thing, every single time. That's the opposite of random. So for decades, programmers had to get creative, and the tricks they invented split into two completely different families. Understanding that split is the key to using RNGs wisely, so let's get into it.
2True random vs pseudorandom — the key distinction
There are two ways to get random numbers, and they couldn't be more different under the hood.
True random number generators (TRNGs)
A true random number generator doesn't calculate anything. It listens to the physical world — and the physical world is gloriously unpredictable. The most famous example is random.org, which has been serving randomness since 1998 by sampling atmospheric noise (yes, the same static you hear between radio stations). Other TRNGs measure thermal noise in electronic circuits, the exact timing of your keystrokes, or even radioactive decay.
The beautiful thing about true randomness: it can never be reproduced. Nobody — not you, not a hacker, not the person who built the device — can rewind the universe and get the same atmospheric static twice. That's also its weakness. It's slow, it needs special hardware, and if your app needs the same "random" sequence twice (say, to replay a game level exactly), you're out of luck.
Pseudorandom number generators (PRNGs)
A pseudorandom number generator is pure math. You feed it a starting number called a seed, it runs that seed through a formula, and out pops a number. Then it feeds that number back into the formula, and out pops the next one — a chain of arithmetic that looks random. The formulas are clever enough that the output passes serious statistical tests: no obvious patterns, no favorites, roughly even spread.
Here's the catch that computing pioneer John von Neumann nailed back in 1951: "Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin." His point was blunt — math isn't random. Give a PRNG the same seed and it spits out the exact same sequence, every time. That's a feature when you want reproducibility (game developers love it), and a disaster when you need secrecy (attackers love it too).
| True random (TRNG) | Pseudorandom (PRNG) | |
|---|---|---|
| Source | Physical chaos — atmospheric noise, thermal jitter, keystroke timing | Math formula + seed value |
| Reproducible? | Never — impossible to replay | Yes — same seed gives the same sequence |
| Speed | Slow — limited by the physical source | Extremely fast — millions of numbers per second |
| Security | Unpredictable by nature | Only safe if "cryptographically secure" (see section 3) |
| Needs special hardware? | Usually yes | No — runs on any device |
| Examples | random.org, hardware RNG chips, lottery ball machines | Mersenne Twister, LCG, Math.random() |
| Best for | Encryption keys, high-stakes draws | Games, simulations, sampling, everyday use |
3How PRNG algorithms actually work
Let's pop the hood. You don't need a math degree for this — the core ideas are surprisingly down-to-earth.
The LCG: randomness from one line of arithmetic
The oldest and simplest PRNG is the linear congruential generator, invented in the late 1940s. Its entire formula fits on a napkin:
Multiply the current number by a, add c, then take the remainder when dividing by m. That remainder is your next "random" number — and it becomes the input for the round after that. Watch it with tiny numbers so you can follow along: take a = 5, c = 3, m = 16, and seed = 7.
Not bad for one line of math. The problem? With small values of m, the sequence repeats fast and patterns show through. Old video games and the C language's classic rand() used LCGs — fine for shuffling a playlist in 1985, not fine for anything serious today.
The Mersenne Twister: the workhorse
In 1997, two mathematicians built something far stronger: the Mersenne Twister (MT19937). Instead of one multiplication, it juggles a giant pool of 624 numbers, twisting and tempering them through a series of bit operations. The payoff is absurd: its sequence doesn't repeat for 219937 − 1 numbers — a number with about 6,000 digits. You could generate numbers every nanosecond until the heat death of the universe and never see it loop.
It's the default in Python's random module, and it runs countless scientific simulations. But it has one famous flaw: it's predictable. Watch 624 consecutive outputs and you can reverse-engineer its entire internal state, then predict every future number. Great for science. Terrible for secrets.
Crypto-grade: randomness you can bet the company on
For passwords, encryption keys and tokens, you need a cryptographically secure PRNG (CSPRNG) — one designed so that even seeing a billion past outputs gives an attacker no edge in guessing the next. Your operating system runs one constantly, sipping entropy from hardware timing jitter, and browsers expose it through crypto.getRandomValues(). That's what powers the generator on our tool page: genuine OS-level unpredictability, not a classroom formula.
| Algorithm | Period (before repeating) | Speed | Secure? | You'll find it in |
|---|---|---|---|---|
| LCG | Short (depends on settings) | Blazing | No | Old games, C's rand(), cheap toys |
| Mersenne Twister | 219937 − 1 (astronomical) | Fast | No | Python random, simulations, games |
| xorshift128+ | 2128 − 1 | Blazing | No | JavaScript Math.random() (Chrome/V8) |
| CSPRNG (OS-level) | Effectively infinite | Fast enough | Yes | crypto.getRandomValues(), password managers, TLS |
4Every real-world use case, from lotteries to classrooms
Random numbers quietly run more of daily life than most people realize. Here's where they actually show up — you've probably used half of these this month without thinking about it.
Games and gambling
This is the obvious one. Slot machines, online poker shuffles, loot drops in video games, dice apps — all RNGs. Casinos take this deadly seriously: their machines use certified hardware generators and get audited, because a predictable slot machine is a lawsuit waiting to happen. Your home board-game night doesn't need that level of paranoia, but the principle is the same: nobody should be able to guess what's next.
Lotteries and raffles
Big national lotteries still use physical ball machines — cameras, auditors, the whole show — because the public has to see fairness happening. But for office raffles, charity draws, and Instagram giveaways, an online generator is the practical answer. Number the entries, draw, done. (We'll walk through the exact steps in section 6.)
Passwords, tokens and security
Every "reset password" link, every two-factor backup code, every session token keeping you logged in — random strings, all of them. This is the one place where only crypto-grade randomness counts. A predictable password-reset token means anyone can hijack accounts, which is why security folks lose sleep over bad RNGs and why you should never roll your own with Math.random().
Science and statistics
Researchers can't test a new drug on all 8 billion people, so they test it on a random sample and generalize. Pollsters do the same with voters. Monte Carlo simulations — used for everything from weather models to nuclear physics — run millions of random trials to approximate answers that are too complex to calculate directly. Bad randomness here doesn't just lose a game; it publishes wrong science.
Classrooms and teams
Teachers use RNGs to call on students fairly, split classes into groups, and randomize quiz question order so neighbors can't copy. Coaches draw tournament brackets. Managers pick who presents first in the Monday meeting. Anytime humans would (consciously or not) play favorites, a random draw keeps things honest.
Everyday decisions
Can't decide between two restaurants? Assign them numbers and let the generator choose. Need a tiebreaker for where the team goes for lunch? Random draw ends the debate in five seconds. It sounds trivial, but "let chance decide" is one of humanity's oldest conflict-resolution tools — older than courts, older than voting.
Sports drafts and shuffling
Fantasy leagues randomize draft order. Card game apps shuffle decks. Music apps shuffle playlists (and then get complaints that the shuffle "isn't random" — more on that in the fairness section). Anytime order matters and nobody should control it, RNGs do the job.
Which RNG do you actually need?
| Your situation | What to use | Why |
|---|---|---|
| Picking a raffle winner | Any decent online generator | Equal odds per ticket is all that matters |
| Board game night / dice app | Any decent online generator | Speed beats perfection here |
| Teacher splitting students into groups | Any decent online generator | Fairness visible to the class is the goal |
| Replaying a game level exactly | Seeded PRNG (Mersenne Twister) | Same seed replays the identical sequence |
| Scientific simulation | Mersenne Twister or better | Huge period, well-tested statistics |
| Passwords, tokens, 2FA codes | Crypto-grade only | Predictability = hacked accounts |
| National lottery | Certified hardware / physical balls | Public trust needs auditing, not just math |
5Fairness, bias and seeds — explained simply
Three ideas cause 90% of the confusion around RNGs. Let's clear them up with plain examples.
Fairness means equal odds, nothing more
A fair generator gives every number in your range the same probability. In a 1–100 draw, each number has exactly a 1% chance — including the number that just came up. This trips people up constantly: after drawing 42, your gut says 42 is "used up" and something else is "due." Nope. The generator has no memory. Drawing 42 twice in a row (a 1-in-10,000 event) is exactly as likely as drawing 42 then 17. Randomness doesn't do karma.
Bias: when the hat has a hole in it
Bias is any systematic tilt — some outcomes quietly winning more than their share. Classic real-world case: a cheap physical die with an air bubble inside, or rounded corners that favor certain faces. In software, bias usually comes from sloppy range-mapping — the infamous modulo bias. Say your generator makes numbers 0–255 (256 values) and you do value mod 100 to get 0–99. Values 0–55 now have three ways to appear (0, 100, 200 → 0) while 56–99 have only two. That's a real, measurable tilt toward low numbers. Good generators sidestep this by discarding out-of-range values instead of wrapping them.
Seeds: the start button you can replay
Remember: a PRNG is deterministic — seed in, fixed sequence out. Most of the time the seed is picked for you (from the clock, or from OS entropy), and you'll never think about it. But seeds are genuinely useful in two cases. Game developers use them so players can share a seed and play the identical procedurally-generated world — Minecraft's famous seeds work exactly this way. Scientists publish their seeds so other researchers can rerun the exact same simulation and check the results. If anyone ever needs to audit your draw, a recorded seed is proof of what happened.
6How to use our free random number generator
Enough theory — let's put it to work. Our generator lives right on this site, it's free forever, and it runs entirely in your browser (your numbers never leave your device). Here's the 30-second version:
- Set your range. Raffle with 500 tickets? Minimum 1, maximum 500. Rolling a d20? Minimum 1, maximum 20.
- Choose how many numbers you want in one go.
- Decide on repeats. Drawing multiple prize winners from the same ticket pool? Turn on no repeats so nobody wins twice. Rolling dice? Leave repeats on — real dice don't remember.
- Hit generate. That's it. Copy the result, or share the page link — the URL carries your settings so anyone opening it sees the same setup.
Try it right now — free, no signup
Pick raffle winners, settle debates, randomize your classroom, or just roll some dice. Crypto-grade randomness, straight from your browser.
🎲 Open the Random Number Generator100% free · No account · Private by design
7Limitations — what RNGs can't do
Random number generators are great tools, but let's be straight about where they fall short:
- They can't make a bad process fair. A random draw from a rigged entry list is still rigged. If the inputs are biased, the output inherits it — randomness only shuffles what you feed it.
- Plain PRNGs can't keep secrets.
Math.random()and the Mersenne Twister are predictable to anyone who looks closely. Never use them for passwords, tokens, or anything an attacker would love to guess. - They don't fix the clustering illusion. A perfect generator will still hand you 7, 7, 7 sometimes — and your audience will still swear it's broken. If perception matters (playlists, game loot), designers sometimes nudge results to feel more random than true randomness. Spotify famously did exactly this.
- They can't prove fairness by themselves. For high-stakes draws, you need the boring stuff around the math: published rules, witnesses or recordings, and ideally a recorded seed or third-party audit. The number is only half the trust equation.
Watch: randomness in motion — dice tumble, numbers flicker, nothing repeats on purpose.
8Frequently asked questions
What is a random number generator?
A random number generator (RNG) is a tool or algorithm that produces a sequence of numbers with no predictable pattern, where each number in the requested range has an equal chance of appearing. Online generators like ours use your device's cryptographic random source, so every draw is independent and unbiased.
What is the difference between true random and pseudorandom numbers?
True random numbers come from unpredictable physical processes — atmospheric noise, thermal jitter, radioactive decay — and can never be reproduced. Pseudorandom numbers come from deterministic math formulas started from a seed: they look random and pass statistical tests, but the same seed always gives the same sequence. For games, raffles and sampling, good pseudorandomness is plenty; for cryptography you need true or cryptographically secure randomness.
Is the Mersenne Twister a good random number generator?
The Mersenne Twister (MT19937) is an excellent general-purpose PRNG with an enormous period of 2^19937 − 1, so it effectively never repeats. It powers Python's random module and countless simulations. But it's not cryptographically secure — observing enough outputs lets an attacker predict the rest — so never use it for passwords, tokens or encryption keys.
How do I run a fair online giveaway with a random number generator?
Number every entry (say 1–500), set the generator's minimum to 1 and maximum to 500, and generate one number — that entry wins. For multiple prizes, enable no-repeats mode and draw one number per prize. Record the draw (a screen recording works great) so everyone can verify it was fair.
Why do I keep seeing the same numbers — is the generator broken?
No — streaks and repeats are normal in true randomness. Drawing 42 twice in a row from 1–100 has exactly the same probability (1 in 10,000) as drawing 42 then 17. People expect randomness to look evenly spread, but real random data clusters. Psychologists call this expectation gap the clustering illusion.
Can I use an online random number generator for passwords?
For casual low-stakes use, a crypto-grade generator built on crypto.getRandomValues() makes genuinely unpredictable values that work fine as passwords. For anything important, use a dedicated password manager instead — it also stores the password, checks its strength, and removes the risk of someone seeing your screen mid-generation.
Keep exploring
Randomness is just one corner of the toolbox. These related tools pair naturally with the guide above:
Related guides
More step-by-step guides on this topic:
