+ 2
whats the difference between "rand" and "srand" function?
rand() and srand()
3 Answers
+ 1
you can't create truly random numbers, so you rely on some outside source of randomness to get random enough number.
rand() function simply returns a number that is based on what is seeded in stl. srand() helps you seed rand(). So you could use something like this
srand(ctime(0));
rand();
rand();
rand(); and now your random will depend on current time of your system. Similarly you could use something else to seed it other than ctime.
+ 1
that was a clear answer thanks!
- 1
â»