srand(time(0));

Hi, ALl!
Please, what is the meaning of (time(0)) in that command?
Why time and why 0?
Many thanks for any usefull links!!

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
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!

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
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...
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
Topic archived. No new replies allowed.