+ 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)?
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.
+ 1
Tibor Santa link doesnt answer completely....plz explain in detail...thanks for answering
+ 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.