0
How come srand() produces same sequence using the same interger? Shouldn't srand change the sequence as true random?
3 Antworten
0
use srand( time( NULL ) );
0
Also, time(0) returns the time passed from 1 jan 1970 until now on milliseconds.
- 2
Imagine a simple math function: y = x, if I enter x=5, then y=5. No matter how many times I enter 5, I will always receive 5.
rand() is no different from this principle, except it's more complex, and outputs a number that has seemingly no relation to thr input. Still, no matter what, if I give the same number, I'll receive the same sequence, just as if I enter 5 in the last function, I'll always receive 5.
now whenever you enter time(0), it outputs the current time, which is hardly the same at any time. So it gives you some randomness into the program, but the rand() function by itself is not random.
Hope this helps.