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

Asked 2 years ago, Updated 2 years ago, 33 views

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

c

2022-09-30 18:05

3 Answers

Although there is no general fact that the standard C land is not recommended, there are a few things to keep in mind.

For example, even if sland is given the same seed, the random sequence generated by different environments can be different.The range of values to return is also implementation dependent.

If older implementations continue to be used for backward compatibility and other reasons, algorithms that are known to have quality problems may still be used.We know that the commonly used linear combination method has a short period and has problems with randomness.

This is not clearly recommended.You must use a cryptographic pseudo-random number generator.This includes the key used for encryption, as well as session tokens.


2022-09-30 18:05

Random number generation in C language

Because pseudo-random numbers are generated from deterministic algorithms, periodicity, predictability, and distribution bias are inevitably generated unlike random numbers.Therefore, it is important to use a high-precision generation algorithm in order to obtain a high-precision analysis in research.


2022-09-30 18:05

There is no definition of methods or algorithms for generating pseudo-random numbers in the C language standard.Therefore, what random numbers are generated depends on the implementation of the C language.If the execution environment changes, reproducibility will disappear, so if reproducibility is required in research, it is necessary to implement pseudo-random numbers independently.
For example, many implementations use linear congruence methods, but the constant values used in the same linear congruence method also change the random sequence generated.Because the constant values used in the implementation may be different, if you want the same results all the time, you will need to implement them on your own.


2022-09-30 18:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.