I don’t understand why srand () generates so similar random numbers between runs!
I am trying to run the following code
srand ( time(NULL) );
int x = rand();
cout << x << endl;
However, instead of the correct random number, I always get almost the same number, which slowly grows over time. So I get numbers like: 11669, 11685, 11701, 11714, 11731.
What am I doing wrong?
I am using Visual Studio 2010 SP1.
Ok, is srand () really that simple? I mean, how can anyone call it a random function?
srand(1) => rand() = 41
srand(2) => rand() = 45
srand(3) => rand() = 48
srand(4) => rand() = 51
....
zsero source
share