How to make random numbers between 2 to 5?

I want to output random numbers 100 times between 2 to 5 but I can't get it.

1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(){
	
	srand(time(0));
	
	for (int a=0;a<100;a++){
		cout<<rand() % 5 + 2<<endl;
	}
}
just change 5 to 4.
Now I get it.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(){
	
	srand(time(0));
	
	for (int a=0;a<100;a++){
		cout<<rand() % 4 + 2<<endl;
	}
}
Topic archived. No new replies allowed.