Random Number Generator

Random Number Generator

Generate one or more random numbers within a range. All generation happens locally in your browser.

Result
Note: Numbers are generated using your browser's cryptographic random number source and are suitable for general use (games, sampling, giveaways). For regulated gambling, lotteries, or cryptographic security purposes, use a certified random number generator.

Random Number Generator: How It Works and When It’s Truly Random

Quick summary: A random number generator produces numbers using either a deterministic algorithm (a pseudorandom number generator, or PRNG) seeded by an initial value, or an unpredictable physical process like atmospheric noise or radioactive decay (a true random number generator, or TRNG). Most everyday online tools use PRNGs, which are fast and statistically random-looking but technically predictable if the seed is known — which matters for anything security-sensitive.

Whether you’re picking a raffle winner, generating a test dataset, or just settling an argument about who does the dishes, a random number generator feels simple on the surface — but the technology underneath varies dramatically depending on what it’s built for. This guide explains the real difference between pseudorandom and true random number generation, how each type actually works, worked examples of the math involved, and when the distinction genuinely matters versus when it doesn’t.

What Is a Random Number Generator?

A random number generator (RNG) is a computational or physical device designed to generate a sequence of numbers that cannot be reasonably predicted better than by random chance (uspto.gov, patent filing on true random number generation methods). Despite the simple-sounding name, random number generators fall into two fundamentally different categories, and knowing which one you’re using matters more than most people realize.

Pseudorandom Number Generators (PRNGs)

A pseudorandom number generator uses a deterministic mathematical algorithm and an initial “seed” value to produce a sequence of numbers that statistically resembles true randomness — without actually being random (wolfssl.com). According to a technical comparison from wolfSSL, PRNGs employ deterministic algorithms that aim to mimic the statistical properties of true randomness, but their output is ultimately predictable if you know the seed: given the same seed, a PRNG will produce the exact same sequence of numbers every time (wolfssl.com).

Everyday software tools rely almost entirely on PRNGs because they’re fast and computationally cheap. According to wolfSSL, pseudorandom number generation in common tools like Python and Excel is based on the Mersenne Twister algorithm, one of the most widely used PRNG algorithms in general-purpose computing (wolfssl.com).

How a PRNG Formula Works (Simplified)

Most PRNGs follow this general process:

  1. Start with a seed value (a starting number — often drawn from the system clock or another semi-variable source)
  2. Feed the seed into a deterministic mathematical formula
  3. Generate an output number
  4. Feed that output back into the formula to generate the next number in the sequence
  5. Repeat to produce a long stream of numbers that pass statistical tests for randomness

Because every step in this chain is deterministic, an attacker who knows the seed and the algorithm can reproduce the exact same “random” sequence — which is why PRNGs, despite being suitably fast for a computer, cannot generate a truly unpredictable number (uspto.gov).

True Random Number Generators (TRNGs)

A true random number generator doesn’t use a formula at all — it measures an unpredictable physical phenomenon and converts that measurement into a number. According to multiple technical sources, common entropy sources for TRNGs include:

  • Thermal (Johnson-Nyquist) noise from electronic components
  • Atmospheric radio noise
  • Radioactive decay of isotopes
  • Interference patterns from ring oscillators
  • Timing of user interactions like mouse movement or keystrokes

(uspto.gov; arxiv.org, “Quantum Random Number Generators”)

Since the underlying physical process is genuinely non-deterministic, a TRNG’s output cannot be recreated or predicted, even with full knowledge of the device and its design (wolfssl.com). This is why cryptographic applications — like generating an encryption key — rely on true randomness rather than an algorithm alone (uspto.gov, patent on SRAM-based TRNGs).

The trade-off is speed: because TRNGs depend on collecting a limited amount of physical entropy, they are considerably slower to generate numbers than PRNGs, which is why most everyday applications don’t use pure TRNGs at all (arxiv.org, “Grokya: a Privacy-Friendly Framework for Ubiquitous Computing”).

Worked Example: Simulating a PRNG-Style Linear Formula

While real-world PRNGs like the Mersenne Twister are far more complex, the basic concept behind an early class of PRNGs (linear congruential generators) can be shown with a simple formula:

Next number = (a × seed + c) mod m

Using illustrative values a = 5, c = 3, m = 16, and a starting seed of 7:

  1. Next = (5 × 7 + 3) mod 16 = 38 mod 16 = 6
  2. Next = (5 × 6 + 3) mod 16 = 33 mod 16 = 1
  3. Next = (5 × 1 + 3) mod 16 = 8 mod 16 = 8

Notice that if you started with the same seed (7) and the same a, c, and m values again, you would get the exact same sequence — 6, 1, 8 — every single time. This determinism is the core limitation of any PRNG, no matter how sophisticated the underlying formula becomes.

Worked Example: Generating a Random Number in a Range

Most practical random number generator tools ask for a minimum and maximum value rather than a raw output. The standard formula for scaling a random value into a specific range is:

Result = Minimum + (Random Value × (Maximum − Minimum + 1))

For example, to generate a random whole number between 1 and 100 (inclusive) from an underlying random value of 0.42 (on a 0–1 scale):

Result = 1 + floor(0.42 × (100 − 1 + 1)) = 1 + floor(42.0) = 43

When the PRNG vs. TRNG Distinction Actually Matters

For most everyday purposes — like picking a name from a hat, generating a practice math problem, shuffling a playlist, or rolling virtual dice for a casual game — a standard PRNG is more than sufficient, since it’s fast, “random enough” for statistical purposes, and passes standard randomness tests.

The distinction becomes genuinely important for:

  • Cryptography and encryption keys — where predictability is a security vulnerability, not just a technicality (uspto.gov)
  • Online gambling and lottery systems — where regulators often require certified TRNGs or cryptographically secure PRNGs to prevent manipulation
  • Scientific simulations requiring true reproducibility — interestingly, some research fields (like high-performance computing and Monte Carlo simulations) actually prefer PRNGs specifically because they’re reproducible with a known seed, making results verifiable by other researchers (arxiv.org, “Reproducibility, Replicability, and Repeatability”)
  • Security-critical authentication systems, where a hybrid approach is common — using a TRNG to generate a genuinely random seed, then a PRNG to rapidly “stretch” that seed into a longer, still cryptographically strong sequence of numbers (wolfssl.com)

Common Misconceptions About Random Number Generators

  • “My computer’s random number generator is completely random.” In most cases, no — unless the specific tool explicitly uses a hardware-based TRNG or an entropy-gathering service, standard software random functions are pseudorandom.
  • “A longer, more complex algorithm means more true randomness.” Not necessarily — a PRNG can be extremely sophisticated and still be fully deterministic and reproducible given its seed and algorithm.
  • “True randomness is always better.” Not for every use case — reproducible pseudorandomness is actually preferred in scientific research specifically because it allows other researchers to verify and replicate exact results.
  • “Random.org and similar atmospheric-noise-based tools work the same way as my calculator’s random function.” They don’t — services built on genuine physical entropy sources (like atmospheric noise) are TRNGs, fundamentally different from the deterministic PRNG functions built into most everyday software (boallen.com).

FAQs

What’s the difference between a pseudorandom and a true random number generator?

A pseudorandom number generator (PRNG) uses a deterministic algorithm and a starting seed to produce numbers that look statistically random but are technically predictable if the seed is known. A true random number generator (TRNG) uses an unpredictable physical process, like atmospheric noise or radioactive decay, to produce genuinely non-deterministic numbers.

Is the random number generator on my computer truly random?

Usually not — most everyday software random functions, including those in tools like Excel and Python, are pseudorandom, based on algorithms like the Mersenne Twister.

Why does cryptography require true random numbers instead of pseudorandom ones?

Because PRNG output is deterministic and can theoretically be predicted or reproduced if the seed and algorithm are known, which creates a security vulnerability for anything relying on unpredictability, such as encryption keys.

Can a random number generator repeat the same sequence of numbers?

Yes, if it’s a PRNG using the same seed value, it will always produce the exact same sequence — this is actually considered a feature in some scientific applications where reproducibility matters.

What sources of physical entropy do true random number generators use?

Common sources include thermal noise from electronic components, atmospheric radio noise, radioactive decay, and interference patterns from ring oscillators.

Related Calculators

Conclusion

A random number generator sounds like a simple tool, but the technology behind it splits into two genuinely different approaches: fast, deterministic pseudorandom algorithms suitable for everyday use, and slower, physically grounded true random number generators built for cryptography and other security-critical work. Understanding which type of random number generator you’re actually using — and why that distinction matters for your specific use case — helps you pick the right tool, whether you’re just shuffling a deck of cards or generating an encryption key that genuinely needs to be unpredictable.