-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom_Number_Generator.cpp
More file actions
84 lines (70 loc) · 2.2 KB
/
Random_Number_Generator.cpp
File metadata and controls
84 lines (70 loc) · 2.2 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "Random_Number_Generator.h"
Generator::Generator(){
MIN_V = 0;
MAX_V = 10;
SEED = 0;
}
Generator::Generator(unsigned int _MIN, unsigned int _MAX){
if(_MIN > _MAX){
int temp = _MIN;
_MIN = _MAX;
_MIN = temp;
}
MIN_V = _MIN;
MAX_V = _MAX;
}
Generator::Generator(unsigned int _MIN, unsigned int _MAX, unsigned int _SEED){
if(_MIN > _MAX){
unsigned int temp = _MIN;
_MIN = _MAX;
_MAX = temp;
}else if(_SEED < _MIN || _SEED > _MAX){
_SEED = _MIN;
}
MIN_V = _MIN;
MAX_V = _MAX;
SEED = _SEED;
}
Generator::~Generator(){}
void Generator::setBaseMin(unsigned int _MIN){
if(MAX_V < _MIN){
throw aghException(1, "The lower limit can not be higher than upper limit.", __FILE__, __LINE__);
}else{
MIN_V = _MIN;
}
}
void Generator::setBaseMax(unsigned int _MAX){
if(MIN_V > _MAX){
throw aghException(1, "The lower limit can not be higher than upper limit.", __FILE__, __LINE__);
}else{
MAX_V = _MAX;
}
}
void Generator::setBaseSeed(unsigned int _SEED){
if(_SEED < MIN_V || _SEED > MAX_V){
throw aghException(2, "The seed value should be between lower and upper limit.", __FILE__, __LINE__);
}else{
SEED = _SEED;
}
}
void Generator::setMin(unsigned int _MIN){
setBaseMin(_MIN);
}
void Generator::setMax(unsigned int _MAX){
setBaseMax(_MAX);
}
void Generator::setSeed(unsigned int _SEED){
setBaseSeed(_SEED);
}
unsigned int Generator::getMin(void){
return MIN_V;
}
unsigned int Generator::getMax(void){
return MAX_V;
}
unsigned int Generator::getSeed(void){
return SEED;
}
void Generator::print (ostream & output){
output << this->operator()() << "\t";
}