+ 2
In This code below for generating random numbers...What is the proper work of time(0)?
2 ответов
+ 3
Normally, you would pass in a nullptr as the parameter for time(). Here is a page you should look at for the time() function: http://www.cplusplus.com/reference/ctime/time/
The function returns a value of type time_t, and the function srand() uses the time_t type parameter, as an int, to set the seed for the rand() function. Here is some reading for that:
http://www.cplusplus.com/reference/cstdlib/srand/
So you should really be using: srand(time(nullptr)); as your seed and not srand(time(0)); if you want as random a number as possible.
+ 2
Thank you williams 😇✌