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

Recommended Answers

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.