Home > Backend Development > C#.Net Tutorial > What does the srand(time(null)) function mean?

What does the srand(time(null)) function mean?

藏色散人
Release: 2019-06-06 11:02:38
Original
19473 people have browsed it

What does the srand(time(null)) function mean?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template