Pseudo-Random vs True Random: What Your Browser’s Random Number Generator Is Actually Doing
The random number your browser just produced was not random. It was calculated. Feed the same starting state into the same algorithm and you get the same number again, every time. That is not a bug, and it is not a scandal — it is how almost every “random” number you will ever meet on a computer is made.
So why do some random numbers get used for session tokens and others for a coin flip in a game? The answer decides when Math.random() is fine and when you have to reach for crypto.getRandomValues(). The question is not whether a number looks random. The question is whether it is unpredictable to someone who wants to guess it.
The short version: “Pseudo-random” and “true random” are not two points on a single scale. They are tools built for different jobs. A pseudo-random generator is fast and reproducible; a true-random generator leans on physical noise. A cryptographically secure generator sits in between and is designed so that even knowing its past outputs does not reveal the next one. For a raffle, any of them is plenty. For a secret, only the last kind will do.
The Three Kinds of Randomness (And Why the Names Are Misleading)
A PRNG (pseudo-random number generator) is an algorithm plus a starting value called a seed. A CSPRNG is also an algorithm plus a seed, but built to resist prediction. A TRNG (true random number generator) pulls from a physical process — electrical noise, timing jitter, radioactive decay — rather than an equation.
The names suggest a ladder from worse to better. That is the trap. These are not three grades of the same thing; they are three answers to three different questions. The clearest proof is in the standards: NIST SP 800-90A defines the DRBG (deterministic random bit generator) that security systems rely on, and “deterministic” is right there in the name. A DRBG is still a PRNG. “Cryptographically secure” does not mean “not pseudo-random.” It means the pseudo-randomness is good enough that an attacker cannot predict it.
| PRNG | CSPRNG | TRNG | |
|---|---|---|---|
| Source | Algorithm + seed | Algorithm + seed | Physical entropy |
| Reproducible | Yes | Yes, if the seed is known | No |
| Predictable | Once the seed leaks | Designed to resist it | Only if the source degrades |
| Speed | Very fast | Moderate | Limited by the source |
| Typical use | Games, simulations | Keys, tokens, nonces | Seeding a CSPRNG |
Notice the last row. In real systems a TRNG rarely feeds you numbers directly — it is too slow. It gathers noise and hands it to a CSPRNG, which stretches that small amount of genuine unpredictability into a fast stream. That detail matters later, because it is exactly what your browser does.
Which one a situation calls for is a practical question, not a philosophical one. If you are splitting a class into groups or drawing a raffle winner, the difference between these three is invisible — see our guide to random number generator use cases. If you are minting a password reset token, it is the whole ballgame.
What Math.random() Actually Does (And Why It’s Not a Bug)
Math.random() is a PRNG. In V8 — the engine inside Chrome, Edge and Node — the underlying algorithm is xorshift128+, chosen for uniform statistics and raw speed, not for resisting prediction. The output passes every “looks random” test you can throw at it, which is precisely why it is dangerous to trust for the wrong job.
None of that is a defect. It is a PRNG being a PRNG, built for games and simulations where an attacker is not part of the model. The problem is developers reaching for it in places an attacker is part of the model — password reset links, invitation codes, anti-CSRF tokens. That misuse is common enough to have its own entry, CWE-338: use of a cryptographically weak pseudo-random number generator.
And it is not theoretical. Public research under the name v8_rand_buster showed that capturing roughly four to six consecutive Math.random() outputs is enough to reconstruct the 128-bit internal state, after which every future value — and, running the state backwards, past ones — can be computed. There is a working proof of concept. So when someone asks is Math.random secure, the honest answer is: not for anything an attacker would gain from guessing. It is a fast, well-behaved PRNG that was never designed to keep a secret.
That is the whole of the Math.random vs crypto.getRandomValues debate in one line: same job title, completely different threat model.
crypto.getRandomValues() — What It Actually Changes
crypto.getRandomValues() does not generate randomness in your browser. It asks the operating system for it. On Linux that means /dev/urandom or the getrandom() system call; on Windows it is BCryptGenRandom. The browser is a courier here, not a source.
The operating system, in turn, does not spin randomness out of nothing. It collects entropy from whatever is genuinely noisy — hardware interrupt timings, thermal noise, dedicated RNG chips on modern CPUs — and feeds that into a CSPRNG, which turns a trickle of true unpredictability into a fast, safe stream. Your JavaScript then receives a slice of that stream. A cryptographically secure random number generator is therefore a chain, and crypto.getRandomValues() is your end of it.
The shapes are different too, and the difference is a clue to intent. Math.random() returns a single floating-point number between 0 and 1. crypto.getRandomValues() fills a typed array you hand it, such as a Uint32Array, with raw random bytes. It is not “a more random float.” It is a different interface for a different purpose — raw material for keys, tokens and salts, not a convenience decimal.
The Seed — The One Concept That Explains Everything
The seed is a PRNG’s starting point. Same seed, same algorithm, same sequence — forever. This single fact explains both the power and the danger of pseudo-randomness, so it is worth sitting with.
In a simulation or a test, reproducibility is a feature. Seed a statistical model with a fixed value and every run is identical, which is how you tell a real effect from noise. Reproduce a tricky bug on demand by replaying the seed that produced it. Reproducibility is the entire reason what is a random seed is a first-class idea in data work.
In a lottery or a token, the same property is a disaster. A “random” draw from a known seed is not random at all — anyone who learns the seed can compute the winning number before it is announced. This is the cleanest way to see the line: reproducibility is a feature when you control who knows the seed, and a catastrophe when you do not.
You have almost certainly used seeds without the label. In Minecraft, the world seed decides the terrain; enter the same seed and you get the same map, down to the first tree. That is a PRNG doing exactly what it promises — turning one small input into a large, structured, fully repeatable “random” world.
What This Means for the Tool You’re Using
Fengvi’s random number generator defaults to crypto.getRandomValues(), the secure path, with a toggle that switches to Math.random(). For raffles, classroom groups and dice rolls the two are practically identical — nobody is attacking your book-club draw. For anything that has to stay secret, the difference is fundamental.
Defaulting to secure while leaving the toggle is the honest design. The secure source is fast enough for nearly everything, but if you are generating ten thousand numbers at once, Math.random() can be measurably quicker, and for that workload the security buys you nothing. The point is to give you the choice with a clear default, rather than quietly assuming your use case. And when the output really does need to be a secret, reach for a password generator built on the same cryptographic source instead of a general number picker.
You do not need to know xorshift128+ from a CSPRNG to pick a raffle winner. But if you have ever wondered why “random” comes in so many flavours, now you know where the lines are — and why the flavour you pick should match the question you are asking.
Frequently Asked Questions
Is crypto.getRandomValues() truly random?
No — it is a CSPRNG seeded from physical entropy sources. It is true in the sense that it is unpredictable to an attacker, not in the sense that it outputs raw physical randomness. In practice that distinction almost never matters.
Why would anyone use Math.random() if it is predictable?
Because for games, simulations and most everyday uses, being predictable to an attacker does not matter. Speed and simplicity matter more, and Math.random() gives you both.
Can I reproduce a random number sequence?
With a PRNG, yes — if you know the seed and the algorithm, the sequence is fully deterministic. With a CSPRNG or a TRNG you generally cannot, by design.
Methodological note: This article was written and fact-checked by the Fengvi Editorial Team following a documented editorial methodology. Algorithm and system-call details reflect publicly documented behaviour of V8, Linux and Windows as of the last-updated date.