hi im writing a program which generates a random # in a function several times in a row from the same function. but i have a problemit always returns the same number. is there anyway to to have it generate a different number each time its called?
Yes. Insert the following statement as the first line of your main() function:
Expand|Select|Wrap|Line Numbers
srand((unsigned)time(0));
This will seed the random number generator based on your computer's system time, guaranteeing a set of distinct random numbers every time you run the program.
Yes. Insert the following statement as the first line of your main() function:
Expand|Select|Wrap|Line Numbers
srand((unsigned)time(0));
This will seed the random number generator based on your computer's system time, guaranteeing a set of distinct random numbers every time you run the program.
thanks im used to VB were all you have to do is use RANDOMIZE.