Pseudorandom vs True Random: How to Tell Them Apart
Random numbers come in two flavors: pseudorandom numbers built by calculation, and true random numbers derived from physical phenomena. Both look nicely scattered, but in real engineering work, missing the distinction leads to mistakes such as:
- needing a reproducible simulation, but the result changes every run
- generating password tokens with a random source that is easy to predict
- treating “passes a statistical test” as proof of true randomness
1. The short answer
Pseudorandom numbers are sequences computed from internal state and an algorithm.
True random numbers are sequences derived from physical phenomena such as thermal noise or electrical jitter.
In practice, however, the safe random numbers used in real systems are not raw physical output. They are the output of a CSPRNG (cryptographically secure pseudorandom number generator) seeded from a physical entropy source.
So it helps to keep three categories straight:
- Ordinary PRNG (pseudorandom number generator)
- CSPRNG / DRBG (cryptographic PRNG)
- NRBG / TRNG (true random number generator backed by a physical entropy source)
2. Terminology
| Type | How it is built | Reproducible | Goal | Good fit |
|---|---|---|---|---|
| Ordinary PRNG | Formula and internal state | Yes | Speed and reproducibility | Simulation, games, tests |
| CSPRNG / DRBG | Cryptographic algorithm + seed | Yes (in theory) | Hard to predict | Key generation, tokens, session IDs |
| True random / NRBG | Physical entropy source | No | Physical unpredictability | Seed supply, authentication devices, audited drawings |
3. What actually differs (four axes)
3.1 Source
- Pseudorandom: an algorithm and internal state
- True random: a physical entropy source
3.2 Reproducibility
- Pseudorandom: same seed, same result (great for testing)
- True random: different result even under the same conditions
3.3 Predictability
- Ordinary PRNG: leaking the seed makes the stream easy to read ahead
- CSPRNG: hard to predict as long as internal state stays protected
- True random: hard to predict when the physical source is healthy, but a faulty sensor changes that
3.4 Speed
- Pseudorandom: fast and steady
- True random: slower, since it requires entropy collection and monitoring
4. How to actually tell them apart
You cannot decide from output alone
Looking at a finite slice of output never proves a sequence is true random. You can always write a program that reproduces the same slice on demand.
Look at the generator design first
- What algorithm is it (a plain PRNG or a DRBG)?
- Where does the seed come from (a constant, or the OS entropy source)?
- Does it reseed?
- Does the entropy source have health checks?
- Which API is being called?
Statistical tests are for spotting defects
Test suites like NIST SP 800-22 are useful for catching obvious bias. Passing them, however, does not prove you have a true random source.
5. Choosing by use case
| Use case | Recommended | Why |
|---|---|---|
| Simulation, games | Ordinary PRNG | Fast and reproducible |
| Tests, bug reproduction | Ordinary PRNG | Same input replays the same path |
| Keys, tokens, session IDs | OS-provided secure random API | Unpredictability is required |
| Audited drawings | Physical RNG | Accountability matters |
| Secure random in a typical app | OS-standard secure API | Safer than rolling your own |
6. Safe random APIs by language
- Windows:
BCryptGenRandom - .NET:
System.Security.Cryptography.RandomNumberGenerator - Linux:
getrandom() - Python: the
secretsmodule (therandommodule is not recommended) - Java:
SecureRandom
7. Common misconceptions
- “If it passes statistical tests, it must be true random.” No. CSPRNGs pass them just fine.
- “True random is always safe.” No. A bad sensor or a flawed design can drop the quality.
- “All pseudorandom is dangerous.” No. CSPRNGs are the core of safe random number generation.
- “
Math.random()is fine for tokens.” No. Looking scattered and being hard to predict are not the same property.
8. A decision flow when you are unsure
- Do you need to reproduce the same result? Yes: ordinary PRNG. No: continue.
- Would prediction by an attacker be a problem? Yes: the OS-standard secure API. No: pick on speed.
- Do you need accountability or audit on the random source? Yes: consider a physical RNG.
- Tempted to roll your own? Reach for the standard API first.
9. Wrap-up
- Pseudorandom is built by calculation; reproducibility is its strength
- True random is built from physical phenomena; entropy is its strength
- Real safe random in production is physical entropy + a CSPRNG
- Judge the generator design, not the appearance of the output
- For security purposes, use the OS or language standard secure API
References
- NIST SP 800-90A Rev. 1: Recommendation for Random Number Generation Using Deterministic Random Bit Generators
- NIST SP 800-90B: Recommendation for the Entropy Sources Used for Random Bit Generation
- NIST SP 800-90C: Recommendation for Random Bit Generator (RBG) Constructions
- NIST SP 800-22 Rev. 1a: A Statistical Test Suite for Random and Pseudorandom Number Generators
- RFC 4086: Randomness Requirements for Security
- Microsoft Learn: BCryptGenRandom function
- Linux man page: getrandom(2)
- Microsoft Learn: RandomNumberGenerator Class
- Python documentation: secrets - Generate secure random numbers for managing secrets
- Oracle Java Documentation: SecureRandom
- IPA: Chapter 3.3 Hard-to-break Cryptography and Use of Pseudorandom Numbers (Japanese)
Related Articles
Recent articles sharing the same tags. Deepen your understanding with closely related topics.
How DLL Name Resolution Works on Windows: A Practical Look at Search Order, Known DLLs, API Sets, and SxS
A practical walkthrough of Windows DLL name resolution covering redirection, API sets, SxS manifests, Known DLLs, the loaded-module list,...
When Windows Admin Privileges Are Actually Required: UAC, Protected Areas, and How to Tell from the Design
A practical guide to when Windows admin rights are truly required, organized around UAC, protected locations, services, drivers, and per-...
How to Isolate Only the Administrator-Required Work in a Windows App
A practical design for splitting the administrator-only work in a Windows app into a separate EXE: an administrator broker pattern coveri...
Best Practices for Avoiding Plaintext Secrets in Windows App Config Files
On Windows desktop apps, leaving passwords or tokens in plaintext config is risky. This post lays out where DPAPI (ProtectedData) actuall...
A Minimum Security Checklist for Windows Application Development
A minimum security checklist for Windows app development (WPF, WinForms, WinUI, C++, C#) covering privileges, signing, secrets, communica...
Related Topics
These topic pages place the article in a broader service and decision context.
Windows Technical Topics
Topic hub for KomuraSoft LLC's Windows development, investigation, and legacy-asset articles.