Random #

Pages: 12
+1 @ Helios.

srand is only being passed time()'s return value. Regardless of the optional 'out' parameter time() takes, it still returns the same thing.

Example:

1
2
3
4
5
6
7
int main()
{
    time_t t;
    cout << time(0) << endl;
    cout << time(&t) << endl;
    cin.get();
}
1351481821
1351481821


As you can see, output is the same with both forms.


To clarify: 't' is not seeding srand(), time()'s return value is. 't' is going unused.
Last edited on
@Helios
@Disch

Thanks for the time(0) info. I thought I read somewhere that time_t t seeded srand, but I guess I misunderstood. Anyway, using the time(0) will make it easier to remember, when I need to use the srand function.
Topic archived. No new replies allowed.
Pages: 12