I see this function many times in different codes,
srand(GetTickCount())
What is it really used for?
I see this function many times in different codes,
srand(GetTickCount())
What is it really used for?
srand
is a function that initializes the random number generator. GetTickCount
is a Windows-specific function (accessible only through its API), which gives you back the number of milliseconds since the computer was last started. These two functions together, what they intend, is to provide a random initial seed so that certain parts of the program present an unpredictable functionality (for example, to distribute letters, choose a series of numbers at random, ...). / p>
Now, as you have highlighted @Paula_plus_plus on numerous occasions ( an example ), from C ++ 11 there are much more random and safe mechanisms than srand
, which happens to be a bad option.