### Random Number between 60 and 100

I need to be able to make a random number between 60 and 100 but my code is not cutting it. I think this should work, but I've gotten numbers a low as 41. If I move either of the numbers up, my random number goes up to like 120. Can someone help me get the correct numbers to put in the code?

 ``123456789101112131415161718192021`` `````` #include #include using namespace std; int main() { int Temp=0; srand (time(NULL)); for(int i = 0; i<=10; i++) { Temp = rand()%60+40; cout<

Also, Could someone give me a crash course on how this format of random numbers works? I looked it up on this site but they use a different format than me and I like mine better. So is the number after the percent the minimum value?
Last edited on
 ``12`` `````` //generates random numbers 60 <= Temp <= 99 Temp = rand()%40+60;``````

EDIT: Or "%41" if you want 100 included.

In general: num = rand() % (how many numbers included in range) + (lowest number in the range)
Last edited on
The reason he has 40 and 60 is because this is the formula
(well mine is 1 higher because he is doing 60-99 not 60-100
 `` `` ``Temp = rand() % ( high - low + 1 ) + low``
Thanks man, worked like a charm
Topic archived. No new replies allowed.