-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgn.h
57 lines (43 loc) · 1.01 KB
/
rgn.h
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
/*
module to define variates
*/
#ifndef RNG_H
#define RNG_H
#include<functional>
#include<random>
template<typename T>
class RNG
{
private:
std::function<T()> randStrat_;
public:
RNG(const std::function<T()>& f): randStrat_{f} {};
T operator() () {return randStrat_(); };
};
template<typename T>
class NormalRNG
{
private:
std::normal_distribution<T> dist_;
std::default_random_engine eng_;
public:
NormalRNG(const RngModel<T>& rngModel): dist_{std::get<0>(rngModel), std::get<1>(rngModel)} {reseed();};
T operator() () {return dist_(eng_); };
void reseed(){
eng_.seed(std::random_device{}());
}
};
template<typename T>
class UniformRNG
{
private:
std::uniform_real_distribution<T> dist_;
std::default_random_engine eng_;
public:
UniformRNG(const RngModel<T>& rngModel): dist_{std::get<0>(rngModel), std::get<1>(rngModel)} {reseed();};
T operator() () {return dist_(eng_); };
void reseed(){
eng_.seed(std::random_device{}());
}
};
#endif