what does time(NULL) and srandom(time(NULL)) do in c ?

Recommended Answers

What part of Computer Science your question is, looks like you posted C code here? I transfer your post to correct forum.

Jump to Post

All 3 Replies

What part of Computer Science your question is, looks like you posted C code here? I transfer your post to correct forum.

time gives the time in seconds. Feeding that to srandom seeds the pseudo random number generator based on the time of day.

<pedantic>
Not time of day, number of seconds since the epoch passed so you get a different seed every time (as long as you don't manage to seed your PRNG twice with-in 1 second).
</pedantic>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.