i used this function to get a random number and now the random numbers are picked in the same order every time the program is run. How can i change the order each time?
int randMid(int low, int high)
{
return low+rand()%(high-low+1);
}
i used this function to get a random number and now the random numbers are picked in the same order every time the program is run. How can i change the order each time?
int randMid(int low, int high)
{
return low+rand()%(high-low+1);
}
change the "seed" to the number generator (rand).
the rand() function is actually a pseudo random number generator meaning that the you get the same sequence each time with the same seed number. This is very useful in some programming areas such as games.
whats a seed
srand()
Go to the FAQs and the function is explained there
the number that starts the "random" generator.
for C/C++ it is
srand(int seed);
usually you use the system time as the seed so the program will run differently each time.
Otherwise you can pick a seed number for predictability.
i put srand(int time); in int main before the random number was chosen and i got a parse error
include time.h at the top and use this srand(time(NULL))