Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Are Random Number Generators and Entropy?

Every key, nonce, salt, and session token starts as a random number. If the generator is predictable, the cryptography built on top of it fails no matter how strong the algorithm.

Illustration for the cybersecurity term Random Number Generators and Entropy
Home / Blog / Cybersecurity Terms / What Are Random Number Generators and Entropy?
17 November 2026

What Are Random Number Generators and Entropy?

What Are Random Number Generators and Entropy?

Cryptography assumes that certain values are unpredictable: private keys, session identifiers, nonces, salts, password reset tokens, and the ephemeral values in a key exchange. Entropy is the measure of that unpredictability, and a random number generator is the machinery that produces it. When the machinery is weak, nothing above it survives, and the failure is invisible — the output still looks random to anyone who does not know how it was produced.

Three Kinds of Generator

Modern operating systems combine the first and third: entropy is harvested from interrupts, device timings, and hardware instructions into a pool, which seeds a CSPRNG that supplies everything else.

Call the Right API

PlatformUseAvoid
Linuxgetrandom(2), /dev/urandomSeeding from the clock or process id
WindowsBCryptGenRandomThe deprecated CryptGenRandom in new code
JavaSecureRandomjava.util.Random, Math.random()
Pythonsecrets, os.urandomThe random module
Node.jscrypto.randomBytes, randomUUIDMath.random()
PHPrandom_bytes, random_intrand, mt_rand, uniqid

One long-standing myth deserves correcting: on Linux, /dev/urandom is the correct choice for cryptographic use once the pool has been initialised. It is not weaker than /dev/random; the blocking behaviour of the latter was based on an entropy accounting model the kernel developers themselves abandoned. The genuine concern is the window before initialisation on first boot, which getrandom(2) handles by waiting.

What Goes Wrong

  1. Debian OpenSSL, 2008. A patch removing uninitialised memory reads to silence a memory checker also removed almost all entropy from seeding. For nearly two years, SSH and TLS keys generated on affected systems came from a pool of about 32,000 possibilities, and every one of them could be enumerated. Keys created in that period had to be regenerated worldwide.
  2. Mining your Ps and Qs, 2012. Researchers scanned the internet and factored RSA keys belonging to around 0.5% of TLS hosts, because embedded devices generating keys at first boot shared primes with one another. The devices had almost no entropy available at the moment they needed it most.
  3. Dual_EC_DRBG. A NIST-standardised generator whose constants were widely believed to contain a backdoor permitting whoever chose them to predict its output. NIST withdrew it in 2014, and the Juniper ScreenOS incident disclosed in December 2015 showed what happens when such a generator is present in deployed network equipment.
  4. Cloned and restored state. Virtual machine snapshots, container images, and forked processes can duplicate a seeded generator, producing identical output in two places. Reseed after fork, after restore, and on first boot.
  5. Application-level shortcuts. Password reset tokens built from a timestamp, session identifiers from a counter, UUIDs generated by a non-cryptographic library, and nonces from rand() are among the most common findings in application assessments.

Testing and Assurance

Statistical test suites such as NIST SP 800-22, Dieharder, and TestU01 can reveal gross bias, but passing them proves very little: a counter encrypted with AES passes every statistical test and is entirely predictable to anyone with the key. Real assurance comes from NIST SP 800-90A, 800-90B, and 800-90C, which specify approved constructions, entropy source validation, and health testing, and from reviewing how the seeding actually works in your deployment.

For most teams the practical rule is short. Never write your own generator. Call the platform CSPRNG. Make sure embedded devices and freshly provisioned instances have a genuine entropy source before they generate long-lived keys. And treat any security-relevant value produced by a non-cryptographic function as a defect, because that is where we usually find it during our web application security services, in token generation rather than in the cryptography itself.

FAQ – Frequently Asked Questions

Is /dev/urandom Safe to Use?

Yes, on any modern Linux system once the pool has been initialised. It uses the same CSPRNG as /dev/random and is not weaker; the old blocking behaviour reflected an entropy estimate the kernel maintainers no longer consider meaningful. Use getrandom(2) where available, since it waits for initialisation and then never blocks.

Why Is Math.random() Unsuitable for Tokens?

Because it is a deterministic generator designed for speed and statistical quality, not unpredictability. An attacker who observes a modest number of outputs can recover the internal state and compute every past and future value. Session identifiers, password reset tokens, and API keys generated that way are predictable and have been exploited repeatedly.

Do Embedded Devices Need Special Attention?

Yes. A device generating keys at first boot has no disk, no user input, and no network timing to draw on, which is how thousands of routers and cameras ended up sharing RSA primes. Use a hardware entropy source or TPM, seed from the manufacturing process, or defer key generation until sufficient entropy is available.

How Much Entropy Does a Key Need?

At least as many bits as the key’s security level: 256 bits of entropy for a 256-bit symmetric key. Once a CSPRNG is properly seeded with that much, it can generate unlimited output safely, so the critical question is the quality of the initial seeding rather than how much randomness is consumed afterwards.

Related Terms

You May Be Interested In These

What Is Credential Stuffing?

Cybersecurity Terms

17 November 2026

What Is Credential Stuffing?

Read More
What Is a Security Operations Centre (SOC)?

Cybersecurity Terms

17 November 2026

What Is a Security Operations Centre (SOC)?

Read More
What Is Data Exfiltration?

Cybersecurity Terms

17 November 2026

What Is Data Exfiltration?

Read More