Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
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.

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.
RDSEED and the generators in TPMs and smart cards are of this type. They are limited in rate.Math.random() and java.util.Random is excellent for simulation and useless for security: observe a few hundred outputs and the entire future sequence is recoverable.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.
| Platform | Use | Avoid |
|---|---|---|
| Linux | getrandom(2), /dev/urandom | Seeding from the clock or process id |
| Windows | BCryptGenRandom | The deprecated CryptGenRandom in new code |
| Java | SecureRandom | java.util.Random, Math.random() |
| Python | secrets, os.urandom | The random module |
| Node.js | crypto.randomBytes, randomUUID | Math.random() |
| PHP | random_bytes, random_int | rand, 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.
rand() are among the most common findings in application assessments.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.
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.
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.
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.
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.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.