Random number generator seed issue

Hey guys, I just signed up for this website, seems its an awesome community for C++, which I plan on doing for fun. Anyhow, I am a beginner programmer, I took an intro class to C++ in highschool, and just started two days ago again for fun (i'm 27).

The problem is that I am using a random number generator with inputs for the high and low end of the random number (for damage range on a weapon in a game) which seeds Srand with the system clock, which is perfect for generating random numbers. However, because the system clock, and therefor Srand only changes every second, when the program generates random numbers, if the user doesn't wait a second inbetween asking for an output, it will remain the same until the next second has passed.

int rng (int damagehigh,int damagelow, int&damdone)
srand (time(NULL));
damdone = (rand() % (damagehigh - (damagelow-1)) + damagelow);
return (damdone);

If this code is sloppy or confusing or inefficient sorry, this is just for fun. This is my function that I use. So basically if I hit enter (to run the function inside the program and execute a round of combat) 6 times in the same second, I'll get the same number 6 times.

Is there a way to make srand change quicker than once per second?

Thanks for any help!!
you only have to declare srand once, after your main. Dont declare it in your function.

#includes <cstdlib>
#includes <ctime>
using namespace std;

int main()
You are a genius, that absolutely fixed the problem, thanks so much!!!!!
it's #include not #includes... lol, i'm not that genius.
Topic archived. No new replies allowed.