In some productsSource codeSuch a statement is often found,
Srand (unsigned (Time (null )));
Why is this actually quite simple.
1. The time () function indicates the number of seconds from 00:00:00 to the current time. The time (null) function indicates obtaining a time. To be precise, it indicates obtaining a pointer address.
2. The srand () function generates random number seeds. When the random number rand () is called, he will check that if the user has called srand (SEED) before, he will call srand (SEED) again) to generate random seed. If srand (SEED) is not called, srand (1) is automatically called once. Therefore, if you want rand () to generate different values for each call, you need to call srand (SEED) once each time, and seed cannot be the same.
Based on the above two points, it is very clear.
Srand (unsigned (Time (null) indicates that random seed is generated to ensure that random values are not repeated when rand () is called.