
Random Number Generation Is Not Random: A Developer's Guide to Entropy
Math.random() is not random. It's a deterministic algorithm that produces numbers that look random but are entirely predictable if you know the internal state. This distinction matters for security, simulation accuracy, and statistical validity. Pseudorandom vs truly random A pseudorandom number generator (PRNG) takes a seed value and produces a sequence of numbers through a deterministic algorithm. Given the same seed, it produces the same sequence every time. JavaScript's Math.random() uses xorshift128+ in V8 (Chrome/Node), which has a period of 2^128 - 1. That means after 2^128 - 1 numbers, the sequence repeats. A truly random number generator uses physical entropy sources: thermal noise, radioactive decay, atmospheric noise, or the timing of hardware interrupts. These are fundamentally unpredictable because they're based on quantum-mechanical processes. For most programming tasks, Math.random() is fine. For cryptography, authentication tokens, or anything security-sensitive, you ne
Continue reading on Dev.to JavaScript
Opens in a new tab




