Hi,
I'm trying to generate 3 random numbers inside a while loop.
The problem I encountered is that I always get the same 3 numbers even after I reseed the number using srand((unsigned )time(NULL));
while (J < 3)
{
srand((unsigned )time(NULL)); //Seed the random number generator.
int Rand1 = rand() % 100 + 1;
srand((unsigned )time(NULL)); //Seed the random number generator.
int Rand2 = rand()% 10 + 1;
srand((unsigned )time(NULL)); //Seed the random number generator.
int Rand3 = (rand() % 34 + 4);
J++;
}
If I put a pause at the end of the while loop then it works, as the time changes,
but I need it to be more frequent.
any help would be greatly appreciated.
Regards,
BB
I'm trying to generate 3 random numbers inside a while loop.
The problem I encountered is that I always get the same 3 numbers even after I reseed the number using srand((unsigned )time(NULL));
while (J < 3)
{
srand((unsigned )time(NULL)); //Seed the random number generator.
int Rand1 = rand() % 100 + 1;
srand((unsigned )time(NULL)); //Seed the random number generator.
int Rand2 = rand()% 10 + 1;
srand((unsigned )time(NULL)); //Seed the random number generator.
int Rand3 = (rand() % 34 + 4);
J++;
}
If I put a pause at the end of the while loop then it works, as the time changes,
but I need it to be more frequent.
any help would be greatly appreciated.
Regards,
BB
Comment