Random Number Generator Guide: When Random Isn't Really Random

True Random vs Pseudo-Random Numbers

Computers are fundamentally deterministic — they follow instructions precisely without any genuine unpredictability. This creates a problem: how do you generate truly random numbers on a machine that operates through pure logic? The answer splits into two categories with very different properties and use cases.

True random number generators (TRNGs) harvest randomness from physical phenomena: thermal noise, radioactive decay timing, atmospheric noise, or quantum effects. These sources produce genuinely unpredictable sequences that even with complete knowledge of all previous outputs, you cannot predict the next number. Our random number generator uses your browser's built-in algorithms.

Random number concept

How Pseudo-Random Number Generators Work

Pseudo-random number generators (PRNGs) use mathematical formulas to produce sequences that appear random but are actually completely deterministic. Given the same starting point (seed), a PRNG will produce the same sequence every time. This predictability is both a feature and a bug depending on the application.

Modern PRNGs like the Mersenne Twister produce sequences that pass rigorous statistical tests for randomness, making them suitable for most applications. The period before the sequence repeats can be astronomically large — the Mersenne Twister has a period of 2^19937-1, a number with over 6,000 digits.

If you seed a PRNG with the same value, you get the same sequence. This reproducibility is incredibly useful for debugging and testing. When a bug only appears with certain random numbers, you can reproduce it exactly by using the same seed that triggered it. This is impossible with true randomness.

PRNG Seeds Explained

A seed is the initial value that kicks off the PRNG's deterministic sequence. Common seeding strategies include using the current timestamp, combining multiple sources of partial randomness (timestamp + process ID + memory state), or cryptographic hash functions of unpredictable data.

Poor seeding creates vulnerabilities. If an attacker can determine your seed, they can reproduce your entire random sequence. This is catastrophic in cryptography — predictable random numbers have compromised encryption systems in the past. Secure PRNGs seed from system entropy pools that collect unpredictable hardware and OS-level data.

For games and simulations, predictable seeding is often fine — sometimes even preferable. A game that shuffles a deck the same way each playthrough when restarted enables speedrun strategies and detailed testing. The right amount of randomness depends entirely on context.

Applications Across Fields

Gaming: Video games use PRNGs for everything from loot drops to enemy AI behavior. Seeded runs allow streamers to share specific game states with viewers. Card games shuffle using PRNGs seeded by hardware randomness when dealt by computers.

Statistics: Monte Carlo simulations use random sampling to solve problems that would be computationally infeasible deterministically. Drug trials, financial modeling, and physics simulations all depend on reliable random number generation.

Cryptography: Here, randomness quality is existential. Encryption keys, session tokens, and authentication nonces must be truly unpredictable. Using weak randomness has compromised real-world security systems, making this one domain where "good enough" random absolutely isn't.