Informational | Operating Systems

Why Linux has TWO random number generators?

Why Linux has TWO random number generators?

In Linux, there are two files that generate random numbers, and using the wrong one could break your security.

What are they?

/dev/random and /dev/urandom are kernel interfaces used to generate random bytes for cryptography: SSH keys, certificates, tokens, etc.

Differences

The difference stems from entropy: the real physical noise that the system collects, such as mouse movements or disk timing.

/dev/random, in its classic design, would block, meaning it would make you wait if it thought it ran out of sufficient “fresh” entropy.

/dev/urandom never blocks: it uses a pseudorandom number generator (CSPRNG) seeded with that entropy, and keeps producing bytes endlessly.

Current Utility

Today, in modern Linux (starting from Linux 5.6), that distinction doesn’t really matter anymore. Once the CSPRNG has enough initial entropy (typically at system startup) it remains cryptographically secure forever.

However, the standard recommendation, even from the kernel developers themselves, is to **use /dev/urandom**, or better yet, if working with C, the getrandom() syscall.

Conclusion

/dev/random could hang waiting for entropy without any real need. /dev/urandom is fast, secure, and is what underlying libraries like OpenSSL use.

linux


Avatar

ItsZariep

Youtuber and programmer, using Linux since 2015

About me


© 2026 ItsZariep

Powered by Tessera for Hugo