I have this to give me random numbers.
1 2 3 4 5
|
int random(int low, int high)
{
srand(time(NULL));
return (rand() % high) + low;
}
|
it works just fine. However, when put into a loop as such...
1 2 3 4
|
vector<int> randoms;
for (int i = 0; i < 100; i++) {
randoms.push_back(random(0, 100));
}
|
I get the same random number printed 100 times. What can I change in order to produce a fresh random number for every call?
Last edited on