Expert Reviewed
Marcus Webb, B.Eng, Applied Mathematics SpecialistUpdated June 1, 2026Our Standards →

Last updated:

Random Number Generator

Generate random numbers instantly with customizable ranges. Free random number generator for lotteries, games, statistics, and decision-making applications.

Random Number Generator

Ad-FreeAI-Powered

Generate random numbers, roll dice, flip coins, pick lottery numbers, draw cards, create teams, and make random selections with our comprehensive generator.

Details

Enter values above to see results.

Want to learn more? Browse our calculation guides and tutorials →

Reviewed by CalculatorApp.me Math & Statistics Team

Random Numbers: The Science of True Randomness

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

What Is a Random Number Generator?

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.

Common RNG Algorithms

Linear Congruential Generator (LCG)
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.

Mersenne Twister (MT19937)
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.

ChaCha20 (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 tests

ChaCha20 is the gold standard for fast, secure random generation in modern systems.

Secure Random (Bounded Integer)
// 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.

PRNG vs. TRNG vs. CSPRNG

PropertyPRNGTRNGCSPRNG
SourceAlgorithm + seedPhysical entropyAlgorithm + entropy seeding
SpeedVery fastSlow (hardware limited)Fast
Predictable?Yes (if seed known)NoNo (forward secrecy)
Crypto safe?NoYesYes
ExamplesMath.random(), Mersenne TwisterRandom.org, /dev/randomChaCha20, AES-CTR, /dev/urandom
Use casesSimulations, games, statsLotteries, key seedsPasswords, tokens, SSL/TLS

History of Random Number Generation

1946

Von Neumann's Middle-Squares

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.

1951

Lehmer Linear Congruential Generator

D.H. Lehmer published the first linear congruential generator (LCG), still the basis of many simple random functions in embedded systems.

1955

RAND Corp publishes 1M Random Digits

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.

1997

Mersenne Twister algorithm

Matsumoto and Nishimura published Mersenne Twister (MT19937) with a period of 2¹⁹⁹³⁷−1 — still the default PRNG in Python, R, and many statistics packages.

2006

NIST SP 800-90A (DRBG Standard)

NIST published the Deterministic Random Bit Generator standard, establishing approved algorithms (HMAC-DRBG, CTR-DRBG) for US government cryptographic randomness.

2022

Linux switches default to ChaCha20

Linux kernel 5.17 switched /dev/urandom and /dev/random to use ChaCha20-based CSPRNG, replacing the legacy Yarrow algorithm.

Key References

RNG Myths vs. Facts

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.

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.

Frequently Asked Questions

What is this random number generator using?
This calculator uses your browser's built-in crypto.getRandomValues() — a CSPRNG — ensuring unpredictable, cryptographically secure numbers.
Is this random number generator suitable for lottery picks?
Yes. The numbers generated are uniformly distributed with no bias, making them as fair as any lottery draw mechanism.
What is a seed in random number generation?
A seed is the initial value used to start a PRNG algorithm. The same seed always produces the same sequence — useful for reproducible simulations.
Can I use this to generate a random password?
The password generator tool is better suited for that — it uses the same CSPRNG with additional character set controls. See the Password Generator in related tools.
What is the difference between uniform and normal distribution?
Uniform distribution: every value equally likely. Normal (Gaussian) distribution: values cluster around a mean with a bell curve. Standard RNGs are uniform; statistical simulations often need normal distributions.
How do I generate a random number in Python?
Use secrets.randbelow(n) for cryptographic use. For statistics: random.randint(a, b) or numpy.random.randint(). Use secrets for security-sensitive applications.
What is modulo bias in random number generation?
When mapping a random integer to a range using modulo (%), numbers at the low end are slightly more likely if the range doesn't divide evenly into the PRNG's output space. Rejection sampling eliminates this.
Are lottery numbers truly random?
Official lottery machines use certified hardware RNGs or physical mechanisms (rotating drums, balls). They are audited regularly to ensure statistical fairness.
What is entropy in computing?
Entropy measures unpredictability. Higher entropy = less predictable = more secure. Operating systems collect entropy from hardware events (keystrokes, disk I/O, network timing).
What is the Mersenne Twister?
The world's most widely used statistical PRNG. Period = 2¹⁹⁹³⁷−1 (a Mersenne prime). Passes most statistical tests but is NOT cryptographically secure.
What does crypto.getRandomValues() do?
A Web Crypto API function that fills a typed array with cryptographically secure random values, sourced from the operating system's CSPRNG (e.g., Windows CryptGenRandom, Linux /dev/urandom).
How many bits of randomness do I need for a token?
At minimum 128 bits for casual security; 256 bits for financial/authentication tokens. This translates to 32 hex characters (128 bits) or 43 Base64 characters (256 bits).

References

Related Calculators

Explore All Math & Statistics Tools

Probability, combinatorics, statistics, and more — powerful math tools for every need.

Browse Math Calculators →