-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.cpp
More file actions
95 lines (74 loc) · 2.49 KB
/
Copy pathrandom.cpp
File metadata and controls
95 lines (74 loc) · 2.49 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
85
86
87
88
89
90
91
92
93
94
95
//random.cpp
#include "random.hpp"
RNG_StdMersenne::RNG_StdMersenne(const int key){
this->key = key;
this->rng_ptr = new std::mt19937(this->key);
this->dist_ptr = new std::uniform_real_distribution<fptype>(0,1);
}
RNG_StdMersenne::~RNG_StdMersenne(){
delete rng_ptr;
delete dist_ptr;
}
fptype RNG_StdMersenne::get_value(){
return (*dist_ptr)(*rng_ptr);
}
RNG_Philox4x32::RNG_Philox4x32(const int key){
this->rng_ptr = new r123::Philox4x32;
this->k[0] = key;
valcounter = 4; //Philox4x32 generates four 32bit random values in each round, this counter determines how many of the four have been used
totalcounter = 0; //this variable is a running index of how often the random number generator has been executed
maxval = pow(2,32)-1;
}
RNG_Philox4x32::~RNG_Philox4x32(){
delete rng_ptr;
}
fptype RNG_Philox4x32::get_value(){
if(4 == valcounter){ //regenerate random values if all four have been used
c[0] = totalcounter;
r = (*rng_ptr)(c, k);
valcounter = 0;
totalcounter++;
}
returnval = r[valcounter++]/maxval;
return returnval;
}
RNG_Philox4x64::RNG_Philox4x64(const int key){
this->rng_ptr = new r123::Philox4x64;
this->k[0] = key;
valcounter = 4; //Philox4x64 generates four 64bit random values in each round, this counter determines how many of the four have been used
totalcounter = 0; //this variable is a running index of how often the random number generator has been executed
maxval = pow(2,64)-1;
}
RNG_Philox4x64::~RNG_Philox4x64(){
delete rng_ptr;
}
fptype RNG_Philox4x64::get_value(){
if(4 == valcounter){ //regenerate random values if all four have been used
c[0] = totalcounter;
r = (*rng_ptr)(c, k);
valcounter = 0;
totalcounter++;
}
returnval = r[valcounter++]/maxval;
return returnval;
}
RNG_Threefry4x64::RNG_Threefry4x64(const int key){
this->rng_ptr = new r123::Threefry4x64;
this->k[0] = key;
valcounter = 4; //Threefry4x64 generates four 64bit random values in each round, this counter determines how many of the four have been used
totalcounter = 0; //this variable is a running index of how often the random number generator has been executed
maxval = pow(2,64)-1;
}
RNG_Threefry4x64::~RNG_Threefry4x64(){
delete rng_ptr;
}
fptype RNG_Threefry4x64::get_value(){
if(4 == valcounter){ //regenerate random values if all four have been used
c[0] = totalcounter;
r = (*rng_ptr)(c, k);
valcounter = 0;
totalcounter++;
}
returnval = r[valcounter++]/maxval;
return returnval;
}