# Why is LCG PRNG chosen to be as c++ rand() function?

The C++ rand() function is an Linear Congruential Generator (LCG) PRNG. my questions are:

2. What are the pros and cons?
3. Is it good for cryptography?

The C++ rand() function (actually C function) is not (intended | designed | standarized) for Cryptographic purposes.

As SEJPM noted in the comments, the rand function comes from C and C++ has no upper restriction for the implementation.

1. What are the pros and cons?
2. Is it good for cryptography?

Long story short answer; don't use it for cryptography. For cryptographic purposes use /dev/urandom

The good; it is fast and small. The bad; it is deterministic, and the seed is small ( as noted by poncho in the comments) that prevents it from producing a cryptographically secure RNG from LCG.

• To add a small comment, apart from cryptography, I believe that even the best LCGs are no longer considered good for, say, Monte Carlo simulations. They're OK when you just need a few random numbers and don't care about the possibility that patterns in them will affect your oucomes. Yes, simple and fast is what they have in their favor. The programmer of the ligrary didn't have to do much work, and figured that if you had a serious need, you'd use something else. – Mars May 10 '19 at 3:34

/dev/urandom is the best approach to generate a seed for cryptography, but sometimes we need a secure deterministic PRNG in order to compute its sequence in two sides using the same /dev/urandom; I'm talking about CSPRNG (Cryptographically Secure Pseudo Random Number Generators). My advice is to look at a Salsa20 implementation (eg. Chacha20). Those are cryptographycally secure algorithms and probably the best you can find. Another options for cryptographic purposes are the following: Blum-Micali, ISAAC, Yarrow and Fortuna. Perhaps we'd like to discuss about which one is the faster among the CSPRNG.

• Mersenne Twister is most certainly not cryptographically secure. It may have perfectly wonderful statistical properties (I'm not an expert there), but you (for example) certainly wouldn't want to use it to do shuffling in a poker game... – poncho Feb 28 at 14:36
• You're right about MT. Let me edit my answer. – Maf Mar 2 at 12:25