So I'm making a game, and in it you're supposed to die at a certain age. I wanted the age to be random, for more spunk. I wanted to age to be in between 60-80. So I used this code:
1 2
int deathage;
deathage = rand() % 80 + 60;
(I know I could have that as one line)
The only problem, is that when I was testing it, by having it print deathage, it showed 114 one time. How do I get it to be just between 60-80.
why do all the extra math (CPU cycles), just assign the value of 60 + the number generated by rand () limited to 0 - 20? That puts it in the limit hi and low, efficiency.... :)