What Is Entropy in Security?
Entropy, in security, is the measure of unpredictability — and unpredictability is what keys, tokens, passwords, and nonces depend on to be secure. If a value that is supposed to be random can be guessed or reproduced, everything built on it collapses. Weak randomness has quietly broken cryptography that was otherwise perfectly sound.
Why does randomness break real systems?#
Because “random” values that are predictable are not secrets at all. Classic failures:
- A session token generated from the current time — guessable, so sessions can be hijacked.
- An encryption key seeded from a predictable value — reproducible, so the key can be recovered.
- A password reset token with too little entropy — brute-forceable.
The attacker does not break the algorithm; they predict its input. This is why “roll your own randomness” is as dangerous as rolling your own crypto.
PRNG vs CSPRNG#
Not all random number generators are safe for security:
PRNG (e.g. Math.random, rand()) | CSPRNG (e.g. getrandom, crypto.randomBytes) | |
|---|---|---|
| Designed for | Speed, statistical spread | Unpredictability |
| Predictable? | Often, from its state | No, even given prior outputs |
| Use for security? | Never | Always |
The rule is simple: any value whose secrecy matters — keys, tokens, salts, nonces — must come from a cryptographically secure generator, seeded from the operating system’s entropy source.
Entropy is the foundation under key management and all cryptography. More at the Security Fundamentals hub.
Frequently asked questions#
Why does randomness matter in security?
Keys, session tokens, salts, and nonces are secure only if they are unpredictable. If an attacker can guess or reproduce the "random" value — because it came from a weak source or a known seed — they can forge tokens, recover keys, or hijack sessions. Predictable randomness has broken otherwise-sound cryptographic systems.
What is the difference between a PRNG and a CSPRNG?
A regular pseudo-random number generator (PRNG) is built for statistical randomness and speed, and is often predictable if you know its state — fine for games, dangerous for security. A cryptographically secure PRNG (CSPRNG) is designed so that outputs cannot be predicted even given previous ones. Always use a CSPRNG for security values.