-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.cpp
47 lines (41 loc) · 828 Bytes
/
2.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
42
43
44
45
46
47
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class RandomInt
{
public:
RandomInt(int ia, int ib);
int operator()();
int operator()(int nb);
int operator()(int na, int nb);
private:
int a, b;
};
RandomInt::RandomInt(int ia, int ib) : a(ia), b(ib)
{
}
int RandomInt::operator()()
{
return a + rand() % (b - a + 1);
}
int RandomInt::operator()(int nb)
{
return a + rand() % (nb - a + 1);
}
int RandomInt::operator()(int na, int nb)
{
return na + rand() % (nb - na + 1);
}
int main()
{
RandomInt r(3, 7);
srand(time(NULL));
//r.operator()()
cout << "random value between 3 and 7 " << r() << "\n";
//r.operator()(10)
cout << "random value between 3 and 10 " << r(10) << "\n";
//r.operator()(23,30)
cout << "random value between 23 and 30 " << r(23, 30) << "\n";
return 0;
}