Please tell me why the random numbers provided by the C language standard are not recommended.

Question: Question:

Please tell me why the random numbers provided by the C language standard are not recommended.

Answer: Answer:

There is no general theory that standard C rand is not recommended, but there are a few things to keep in mind.

Standard C does not specify implementation

For example, even if you give srand the same seed, the random number sequence generated may be different in different environments. The range of values ​​to return is also implementation dependent.

Good quality pseudo-random number generators are not always used

If the old implementation continues to be used in terms of backward compatibility, etc., the algorithm that is known to have quality problems may be used as is. The commonly used linear congruential method has been found to have short periods and problems with randomness.

Do not use for security purposes

Not explicitly recommended in this regard. You must use a cryptographically pseudo-random number generator. This includes not only the key used for encryption, but also the session token.

Scroll to Top