+ 6
Can anyone explain me how srand works to give different output every time
3 odpowiedzi
+ 10
srand does not give you a different result every time. if you use the same srand value you will continue to get the same results each time you produce random numbers. srand basically sets up the list of random numbers to be used by defining the seed that random will use when pulling numbers. it is often set to the current time because this number is constantly changing and thus producing a new set of random numbers each use
+ 2
You need to connect the <ctime> library
+ 2
rand () uses a seed number to produce a number. srand () sets the seed number that rand uses. Using time(nullptr) makes it as close to random as possible.