-
Notifications
You must be signed in to change notification settings - Fork 2
/
random numbers.cpp
41 lines (31 loc) · 935 Bytes
/
random numbers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//Generate random numbers within a given range;
//generate completely random numbers
// rand();
//generate random numbers from 0 to 99
// rand()%100;
//generate random numbers from 1 to 100
// rand()%100 + 1;
//generate random numbers from 20 to 50
// rand()%31+ 20; //basically (50 - 20 + 1)
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(void)
{
int n;
//number of iteration/ how many random numbers to generate
int i= 10;
//upper and lower limits for creating random numbers
int lower= 2;
int upper= 10;
cout<< i << " random numbers between "<< lower << " and " << upper<<"\n\n";
//initialing random seed
//so on every start of the program the rand function will return new random number
srand(time(NULL));
while(i--){
n= rand()%(upper-lower+1) + lower;
cout<< n <<endl;
}
return 0;
}