May I know the meaning or even how to read this:
srandom( time( NULL ) )?
NULL
A null pointer. Zero. Points to nothing.
time(NULL)
The time
function returns the current timestamp as an integer. It accepts an input argument. If the argument is not null, the current time is stored in it.
srandom(time(NULL))
The s
means "seed". srandom
means "seed the random number generator". It takes an integer as input, reset the PRNG's internal state derived by the input to generate a sequence of random numbers according to it. The seed is sometimes used to ensure 2 sequences of random numbers are the same, to reproduce an equivalent testing condition.
In general, you just put some always changing value there to avoid having the same sequence every time the program is started. The current timestamp is a good value, so time(NULL)
is used as the input.
The meaning is to initialize the random seed with the current time. time(NULL) returns the current time. srandom() initializes random seed.
srandom
is a function that initializes the random number generator.
It takes a seed value, which in this code is time(NULL)
, which is the current time.
This is read, "srandom of time of null".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With