0

What is the difference bwtween srand() and rand() functions in C++

7th Aug 2017, 4:03 PM
Anjana S. Arjunan
Anjana S. Arjunan - avatar
3 Respuestas
+ 3
rand() generates pseudo-random numbers, that means numbers that look random but are not. srand() "seeds" this generator, that means if you call srand in two different programs with the same number as a seed, rand() will then spit out the same numbers over and over again. That's why you commonly see "srand(time(NULL))", so the seed is different every time you run the program and you get different numbers from rand(). As soon as you know your way around C++, you should stop using rand/srand altogether, and use <random> instead. http://www.cplusplus.com/reference/random/
7th Aug 2017, 4:24 PM
Schindlabua
Schindlabua - avatar
0
Thank you for your answer. It was really helpful.
8th Aug 2017, 1:10 PM
Anjana S. Arjunan
Anjana S. Arjunan - avatar