The statement in C language srand( (time(NULL) ) ;
means setting a random seed, and the random seed can be guaranteed to be different every time it is run.
In C language, the rand() function can be used to generate random numbers, but this is not a real random number, it is a pseudo-random number. It is based on a number. We can call it a seed, which is a benchmark. A coefficient calculated based on a certain recursive formula, but this is not a true random number. When the computer is turned on normally, the value of this seed is determined, unless you destroy the system in order to change the value of the seed.
Therefore, C provides the srand() function, whose prototype is void srand( int a)
. It is used to change this seed value.
srand( (time(NULL )) The time(NULL) function is to get the number of seconds from January 1, 1900 to the present, so that each time the program is run, different random numbers can be guaranteed.
Related tutorial recommendations: "C Video Tutorial"
The above is the detailed content of What does the srand(time(null)) function mean?. For more information, please follow other related articles on the PHP Chinese website!