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);

}

Printable View

- 01-06-2002diaperdandyrandom numbers
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);

} - 01-06-2002taylorguitarman
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. - 01-06-2002diaperdandyseed
whats a seed

- 01-06-2002Fordy
srand()

Go to the FAQs and the function is explained there - 01-06-2002taylorguitarman
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. - 01-06-2002diaperdandyah
i put srand(int time); in int main before the random number was chosen and i got a parse error

- 01-06-2002golfinguy4
include time.h at the top and use this srand(time(NULL))