What does time(NULL) mean in the following :
srand48((long int)time(NULL)) ?
I see it being used in srand48 when we don't want a seed value.
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.
Sign up to join this communityAccording to this answer on Stackoverflow, the function time
is normally passed a pointer to a time_t
object (or struct) which it fills up with the current time. If you pass it null
, however, you will just be handed the current time.
So srand48((long int)time(NULL))
can be translated to (in English):
Call srand48 with the current time reported by 'time' casted to a long integer
A long integer is then just an 8 bit integer.
Essentially you are just calling srand48
with the current time, the effect of which is a non-default seed value.