In This code below for generating random numbers...What is the proper work of time(0)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

In This code below for generating random numbers...What is the proper work of time(0)?

https://code.sololearn.com/cGPY0uME9YPS/?ref=app

16th Jun 2017, 3:24 AM
Prahar pandya
Prahar pandya - avatar
2 Answers
+ 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.
16th Jun 2017, 4:37 AM
Zeke Williams
Zeke Williams - avatar
+ 2
Thank you williams 😇✌
16th Jun 2017, 5:13 AM
Prahar pandya
Prahar pandya - avatar