-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrng.cpp
68 lines (54 loc) · 1.16 KB
/
rng.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <cstdlib>
#include <time.h>
#include <iostream>
#include <cstdlib>
#include "rng.h"
long int getCurrentTime(){
time_t t1 = time(0);
return (long int)t1;
}
int TRNG::getMin(){ return min; }
int TRNG::getMax(){ return max; }
int TRNG::getDiff(){ return diff; }
void TRNG::setMin(int a){ min = a; setdiff(); }
void TRNG::setMax(int a){ max = a; setdiff(); }
void TRNG::setdiff(){ this->diff = max-min; }
void TRNG::swap(int *a, int *b){
if(*a>*b){
int c = *a;
*a = *b;
*b = c;
}
}
void TRNG::setup(int *min,int *max){
swap(min,max);
setMin(*min);
setMax(*max);
this->diff = *max-*min;
this->key = 1;
}
TRNG::TRNG(int min,int max,Flags values){
setup(&min,&max);
//printf(values);
setseed(values);
}
TRNG::TRNG(int min,int max){
setup(&min,&max);
}
TRNG::TRNG(int a){ // testing constructor
std::cout << getCurrentTime() << "" << a << std::endl;
}
void TRNG::setseed(Flags values){
if(!values){
key = 1;
}
if(values & NONE){
key = 1;
}
std::cout << "flags assigned: "<< values << std::endl;
}
int TRNG::rand(){
int rand = std::rand()*key;
//std::cout << diff << std::endl;
int ret = (rand%diff+min);
}