Are Random Number Generators Truly Random?

How-to basics · Updated November 23, 2026

No, standard random number generators (RNGs) are not truly random—they are deterministic algorithms that produce sequences that only appear random. However, hardware-based generators that measure physical processes (like radioactive decay or atmospheric noise) can be truly random, because their output depends on unpredictable quantum or chaotic events.

What People Actually Mean by “Random”

In everyday language, “random” means unpredictable and lacking pattern. But in mathematics and computer science, randomness is defined more rigorously. A sequence is considered random if no algorithm can predict the next number better than chance, given all previous numbers. This is called computational indistinguishability. For most practical uses—like shuffling a playlist or picking a lottery number—you don’t need true randomness; you just need a sequence that passes statistical tests for uniformity and independence.

There are two broad categories of RNGs:

  • Pseudo-random number generators (PRNGs): Algorithms that use a mathematical formula to produce a long sequence of numbers. They start from a seed value and then generate numbers deterministically.
  • True random number generators (TRNGs): Hardware devices that sample physical phenomena, such as thermal noise in a resistor, the timing of radioactive decays, or even the jitter in a computer’s clock.

How Pseudo-Random Number Generators Work

Most software RNGs are PRNGs. A common example is the linear congruential generator (LCG), which uses the formula:

Xn+1 = (a * Xn + c) mod m

Here, a, c, and m are constants, and X is the current value. The sequence repeats after at most m steps. Modern PRNGs like the Mersenne Twister (used in Python and many other languages) have much longer periods—219937−1—but they are still deterministic.

Because PRNGs are deterministic, if you know the seed and the algorithm, you can predict the entire sequence. That’s why they are unsuitable for cryptography unless they are designed as cryptographically secure PRNGs (CSPRNGs), which are computationally infeasible to predict even if you know the algorithm but not the seed.

True Randomness from Hardware

True random number generators (TRNGs) exploit physical processes that are inherently unpredictable. For example, a simple TRNG might measure the voltage fluctuations (thermal noise) across a semiconductor junction. Another approach uses the timing of radioactive decay events—since the exact moment a nucleus decays is governed by quantum mechanics and is fundamentally random.

Some TRNGs use chaotic systems, like a double pendulum or a turbulent fluid, but these are less common because they are harder to calibrate. The key point is that TRNGs do not use a seed or an algorithm; their output is not reproducible even if you run the same device twice.

Why Software RNGs Are “Good Enough” for Most Tasks

For most applications, PRNGs are perfectly adequate. They are fast, cheap, and produce sequences that pass statistical tests like the Diehard tests or the NIST Statistical Test Suite. These tests check for uniformity, independence, and lack of patterns. If a PRNG passes them, it is considered statistically random for non-security purposes.

Examples of everyday uses:

  • Shuffling a music playlist or a deck of cards in a video game.
  • Simulating dice rolls in board games.
  • Generating random sample data for statistical analysis.
  • Creating random colors or positions in computer graphics.

In these cases, even a simple PRNG with a good seed is fine because the user cannot predict the sequence without knowing the seed, and the seed is often taken from the system clock or other variable data.

When You Need True Randomness: Security and Cryptography

Cryptography is the one area where pseudo-randomness is not enough. If an attacker can predict the random numbers used to generate encryption keys, they can break the encryption. That’s why secure systems use cryptographically secure pseudo-random number generators (CSPRNGs) or TRNGs.

A CSPRNG is a PRNG that is designed to be unpredictable even if the attacker knows the algorithm and has seen many previous outputs. Examples include ChaCha20 and AES-CTR based generators. Operating systems provide CSPRNGs to applications: on Windows, CryptGenRandom or BCryptGenRandom; on Linux, /dev/urandom or getrandom().

For high-stakes applications like generating SSL/TLS keys, cryptocurrency wallets, or lottery draws, TRNGs are often used. For instance, many online casinos use TRNGs certified by independent testing labs to ensure fairness.

Common Misconceptions About Randomness

One common misconception is that a random sequence must have no patterns. That is false—a truly random sequence can contain long runs of the same number, just by chance. For example, flipping a fair coin 10 times could produce 10 heads in a row; that outcome has a probability of 1/1024, but it is still possible.

Another misconception is that “random” means “uniformly distributed” in the short term. In the short term, random numbers can cluster or show streaks. Only over a large number of trials does the distribution approach uniform. This is known as the law of large numbers.

Also, people often confuse pseudo-random with random in everyday conversation. When a programmer says “random,” they usually mean a PRNG. When a physicist says “random,” they might mean a TRNG. Clarifying the context avoids confusion.

How to Choose the Right RNG for Your Project

Choosing an RNG depends on your needs:

  • Non-security applications (games, simulations, sampling): Use a standard PRNG like the Mersenne Twister or the random module in your language. Seed it with a value from the system clock or a hardware entropy source if available.
  • Security applications (passwords, tokens, encryption keys): Use a CSPRNG provided by your operating system or a well-vetted library like secrets in Python or crypto/rand in Go.
  • High-stakes fairness (lotteries, online gambling): Use a TRNG or a CSPRNG with a public and verifiable seed. Some systems use a hybrid: a TRNG seeds a CSPRNG, and the seed is published after the draw to allow verification.

For most developers, the simplest rule is: never roll your own RNG for security. Use the built-in CSPRNG of your platform.

Frequently Asked Questions

Can a computer generate truly random numbers?

Not by itself, because a computer is a deterministic machine. But it can use hardware devices that sample physical randomness, like thermal noise or radioactive decay. Most computers have a hardware RNG chip (e.g., Intel’s RdRand) that provides true random bits, which are then used to seed PRNGs.

Is the random function in Excel truly random?

No. Excel’s RAND() and RANDBETWEEN() functions use a pseudo-random number generator. They are fine for simulations and sampling, but not for cryptography. Excel also recalculates them every time the sheet changes, so they are not suitable for generating a list of fixed random numbers unless you copy them as values.

Why do random number generators need a seed?

A PRNG needs a seed to start its sequence. The seed determines the entire sequence. If you use the same seed, you get the same sequence, which is useful for debugging or reproducible experiments. For different sequences, you need a different seed—often taken from the system time or a hardware entropy source.

What is the difference between a PRNG and a CSPRNG?

A PRNG is designed for speed and statistical randomness, but its output can be predicted if the seed is known. A CSPRNG is designed to be unpredictable even if the algorithm is known and the attacker has seen many outputs. CSPRNGs are slower but are required for security-sensitive tasks.

Can a random number generator be biased?

Yes. A biased RNG produces some numbers more often than others. This can happen due to hardware flaws, poor algorithm design, or improper seeding. Statistical tests can detect bias. For example, a simple modulo operation on a range that isn’t a power of 2 can introduce bias if the underlying generator’s range isn’t evenly divisible by the target range.

How can I test if a random number generator is truly random?

You can run statistical tests like the Diehard tests, the NIST suite, or simpler tests like frequency, runs, and autocorrelation. These tests check for uniformity and independence. However, passing these tests does not guarantee true randomness—only that the sequence has no obvious patterns. For true randomness, you must rely on the physical source.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.