srand(time(0));

Mar 11, 2014 at 7:40am
Hi, ALl!
Please, what is the meaning of (time(0)) in that command?
Why time and why 0?
Many thanks for any usefull links!!

Mar 11, 2014 at 8:46am
Read this:

http://www.cplusplus.com/reference/ctime/time/?kw=time

The result is the current time in seconds.

So you can either provide a pointer to a variable where the result is stored or a null pointer. Either way the result is the current time, hence usually a null pointer is provided
Mar 11, 2014 at 1:04pm
Hello!
I think, U misunderstood my question!
I ment the command:

srand

that is for generating random numbers.
What does this have together with timer(s)?

Many thansk!

Mar 11, 2014 at 1:18pm
Surely you can read the description of srand and what is the purpose of its parameter?

PS. You did ask "why 0" and that is a question about 'time', not about 'srand'.
Last edited on Mar 11, 2014 at 1:20pm
Mar 11, 2014 at 3:49pm
Hi!

srand (time(NULL))

srand(1)

it means:
time(0) is standing instead of 1=> time(o) is just a certain NUMERICAL VALUE , diferent from f.e. 1?;)

Asking just to avoid complicating, for now...
Mar 11, 2014 at 5:18pm
The point is that time(NULL) will return a different numerical value every time you run your program. It's a way of making sure that you're always seeding the randomizer with a different number every time.
Last edited on Mar 11, 2014 at 5:19pm
Topic archived. No new replies allowed.