Computer Science - Object Oriented Programming Using C++ - Discussion

Discussion Forum : Object Oriented Programming Using C++ - Section 2 (Q.No. 26)
26.
Which of the following statements uses the computer's clock to initialize the random number generator?
srand(time);
srand(time(NULL));
time(srand);
time(srand(NULL));
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Surya said:   7 years ago
rand() is to generate a random number.

You can pass seed value to random function but you have to use srand() in that case, prototype of srand() is Void srand(int seed).

It is defined in <cstdlib> header file.

Seed is just an integer number here, nothing more.
The time() function returns the number of seconds since 00:00 hours, Jan 1, 1970 UTC (i.e. the current unix timestamp).

So time(0) produce different integer value every second.
And you can pass it in srand().

time(0) and time(null) are same, both produce the same result.
(1)

Priyanka said:   9 years ago
Can any one tell about it?

Ranbir said:   8 years ago
Can you please explain?

Suvojeet Dutta said:   1 decade ago
Please describe.

Post your comments here:

Your comments will be displayed after verification.