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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  #include <iostream>
#include<ctime>
using namespace std;

int main()
{
	int Temp=0;
	 srand (time(NULL));


	for(int i = 0; i<=10; i++)
	{
	 Temp = rand()%60+40;
	 cout<<Temp<<endl;
	}



	system("pause");
	return 0;
}



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
1
2
 //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.