-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinear_Congruential_Generator.cpp
More file actions
37 lines (30 loc) · 1.02 KB
/
Linear_Congruential_Generator.cpp
File metadata and controls
37 lines (30 loc) · 1.02 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
#include "aghInclude.h"
LinearGenerator::LinearGenerator(unsigned int _MIN, unsigned int _MAX, unsigned int _SEED, unsigned int _a, unsigned int _b):Generator(_MIN, _MAX, _SEED){
this->setA(_a);
this->setB(_b);
}
LinearGenerator::~LinearGenerator(){}
void LinearGenerator::setA(unsigned int _a){
if(_a < 1 || _a > this->getMax()){
_a = 1;
}
a = _a;
}
int LinearGenerator::getA(){
return a;
}
void LinearGenerator::setB(unsigned int _b){
if(_b < 1 || _b > this->getMax()){
_b = 1;
}
b = _b;
}
int LinearGenerator::getB(){
return b;
}
int LinearGenerator::operator() (){
int randomNumber = ((a * (this->getSeed())+b) % this->getMax());
randomNumber = this->getMin() + randomNumber % (this->getMax()-this->getMin()+1);
this->setSeed(randomNumber);
return randomNumber;
}