Well that code is missing a > after the
. But anyways...
function is explain in detail here:
Basically it returns current time in seconds since the epoch (typically Jan 1, 1970... but it may vary depending on implementation). The
is passing a null pointer for the parameter to time() since we don't need it.
So that explains what
is doing. That chunk returns a
with the current time.
That time_t value is then put in a
which converts it from a
So that explains
... it's the current time as an unsigned int.
That time is then passed to srand, which takes an unsigned int as its parameter.
srand is explained in detail here:
But basically what it does is "seeds" (or "initializes") the random number generator used by rand(). rand() does not actually generate random numbers... but rather uses a mathematical formula to produce a sequence of numbers which appear random. The 'seed' determines where it starts in that sequence.
So by seeding with the current time... you are ensuring that you get a different sequence of random numbers each time the program is started (unless the program is started multiple times in the same second... in which case time() will give you the same time and you'll get the same seed and therefore the same random sequence).
It seeds rand so you don't get the same numbers every time you run the program.