Reviewed by CalculatorApp.me Math & Statistics Team
PRNGs vs. TRNGs, entropy sources, cryptographic security, and the math of fair randomization.
CSPRNG
Cryptographically secure pseudorandom generator
256 bits
Typical entropy for secure token generation
Mersenne Twister
Most widely used PRNG algorithm (period 2¹⁹⁹³⁷−1)
1955
Year RAND Corp published 1,000,000 Random Digits
Generate random numbers, roll dice, flip coins, pick lottery numbers, draw cards, create teams, and make random selections with our comprehensive generator.
Enter values above to see results.
Explore our in-depth guides related to this calculator
Everything you need to know about mortgages — calculate payments, compare rates, understand amortization, and plan your home purchase with expert-reviewed tools.
Expert-reviewed guide to BMI calculation, healthy weight ranges, limitations of BMI, and alternative health metrics. Includes free BMI calculator.
Comprehensive tax planning guide with free calculators. Covers federal tax brackets, deductions, credits, and strategies to minimize your tax burden.
A random number generator (RNG) produces a sequence of numbers that cannot be predicted better than by chance. Computers — being deterministic machines — cannot produce truly random numbers without a physical entropy source, so they use pseudorandom number generators (PRNGs): algorithms that produce statistically random-appearing sequences from a seed value.
True random number generators (TRNGs) harvest entropy from physical processes: thermal noise, radioactive decay, atmospheric noise, or mouse movement timing. Services like Random.org use atmospheric noise to produce genuine randomness passed by all NIST statistical tests.
RNGs are critical in cryptography, statistical sampling, simulations, gaming, lotteries, key generation, and any application requiring unpredictability.
X(n+1) = (a × X(n) + c) mod m Common params (Knuth MMIX): a = 6364136223846793005 c = 1442695040888963407 m = 2⁶⁴ Fast, simple. NOT cryptographically secure.
LCGs fail many randomness tests if parameters are poorly chosen. Never use for security.
Period: 2¹⁹⁹³⁷ − 1 State: 624 × 32-bit integers Init: seeded with 32-bit value Twist: XOR, shift operations Outputs: 32-bit or 64-bit integers Default PRNG in Python, Ruby, R, MATLAB
Passes Diehard and NIST tests. Used for simulations & statistics. Not CSPRNG.
Uses 256-bit key + 64-bit nonce
20 quarter-round ARX operations
Outputs keystream blocks (512-bit)
Used by: Linux /dev/urandom (2022+)
TLS 1.3, WireGuard VPN
Passes: all NIST 800-22 testsChaCha20 is the gold standard for fast, secure random generation in modern systems.
| Property | PRNG | TRNG | CSPRNG |
|---|---|---|---|
| Source | Algorithm + seed | Physical entropy | Algorithm + entropy seeding |
| Speed | Very fast | Slow (hardware limited) | Fast |
| Predictable? | Yes (if seed known) | No | No (forward secrecy) |
| Crypto safe? | No | Yes | Yes |
| Examples | Math.random(), Mersenne Twister | Random.org, /dev/random | ChaCha20, AES-CTR, /dev/urandom |
| Use cases | Simulations, games, stats | Lotteries, key seeds | Passwords, tokens, SSL/TLS |
John von Neumann proposed the 'middle-squares method' — take a number, square it, extract the middle digits — as the first general PRNG algorithm for computers.
D.H. Lehmer published the first linear congruential generator (LCG), still the basis of many simple random functions in embedded systems.
RAND Corporation published 'A Million Random Digits with 100,000 Normal Deviates' — a physical book of random numbers generated by a randomizing machine, used in simulations and statistics.
Matsumoto and Nishimura published Mersenne Twister (MT19937) with a period of 2¹⁹⁹³⁷−1 — still the default PRNG in Python, R, and many statistics packages.
NIST published the Deterministic Random Bit Generator standard, establishing approved algorithms (HMAC-DRBG, CTR-DRBG) for US government cryptographic randomness.
NIST SP 800-90A
Official US government specification for deterministic random bit generators used in cryptographic applications.
Matsumoto & Nishimura 1998
The seminal paper introducing the MT19937 algorithm, still the most widely deployed statistical PRNG globally.
Random.org
Generates randomness from atmospheric radio noise. Passes all NIST 800-22 statistical tests for randomness.
Bernstein et al.
Specifies ChaCha20 as a CSPRNG and stream cipher widely used in TLS 1.3, WireGuard, and Linux.
Math.random() in JavaScript is cryptographically secure.
Math.random() uses a PRNG (not CSPRNG). For passwords, tokens, or security-sensitive values, use window.crypto.getRandomValues() or crypto.randomBytes() (Node.js).
Repeating the same 'lucky' numbers improves lottery odds.
Each lottery draw is independent. Prior numbers have zero influence on future draws. All number combinations have identical probability.
Computers can generate truly random numbers.
Deterministic computers generate pseudorandom numbers. True randomness requires a physical entropy source (thermal noise, radioactive decay, atmospheric noise).
More decimal places in a PRNG seed means better randomness.
Probability, combinatorics, statistics, and more — powerful math tools for every need.
Browse Math Calculators →Last updated:
// Rejection sampling for fair // distribution without modulo bias: range = max − min + 1 min_valid = (2³² mod range) loop: r = secure_random_32bit() if r >= min_valid: return (r mod range) + min
Naive 'r mod range' creates modulo bias for non-power-of-2 ranges. Rejection sampling is correct.
Linux kernel 5.17 switched /dev/urandom and /dev/random to use ChaCha20-based CSPRNG, replacing the legacy Yarrow algorithm.
The quality of randomness depends on the algorithm, not seed length. A good CSPRNG with a short seed is far superior to a weak algorithm with a long seed.
Advanced math operations