+ 1

what is significance of NULL in srand(time(NULL))?

what if i change NULL to any other number?also what if i just skip time() and just write srand(98)?

4th Jan 2022, 5:35 AM
gaurav kumar
gaurav kumar - avatar
3 Antworten
+ 3
You can check this in the language specification. https://www.cplusplus.com/reference/cstdlib/srand/ A pseudorandom number generator will create the same sequence of values, when given the same seed.
4th Jan 2022, 7:08 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Tibor Santa link doesnt answer completely....plz explain in detail...thanks for answering
5th Jan 2022, 3:33 AM
gaurav kumar
gaurav kumar - avatar
+ 1
Read the other half here: https://en.cppreference.com/w/cpp/chrono/c/time time(NULL) will typically be a large integer number, the current amount of seconds that have passed since Epoch. So if you pass this to srand, every time the random numbers will be different when you run the program at different instants of time. If you pass a constant like 98, you will get the same sequence of "random" numbers every time. This can be useful for testing your code.
5th Jan 2022, 5:23 AM
Tibor Santa
Tibor Santa - avatar