-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyRand.cpp
More file actions
69 lines (58 loc) · 1.49 KB
/
Copy pathmyRand.cpp
File metadata and controls
69 lines (58 loc) · 1.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
//
// myRand.cpp
// HaploCount
//
// Created by Thomas Wong on 15/2/19.
//
#include "myRand.h"
// constructor
MyRand::MyRand(int inSeed) {
seed = inSeed;
#ifdef USE_BOOST
generator = boost::mt19937(seed);
distribution = new uniform_real<>(0.0,1.0);
#else
generator = default_random_engine(seed);
distribution = new uniform_real_distribution<double>(0.0,1.0);
#endif
}
MyRand::MyRand() {
seed = (unsigned) chrono::system_clock::now().time_since_epoch().count();
// seed = 7777777;
#ifdef USE_BOOST
generator = boost::mt19937(seed);
distribution = new uniform_real<>(0.0,1.0);
#else
generator = default_random_engine(seed);
distribution = new uniform_real_distribution<double>(0.0,1.0);
#endif
}
// destructor
MyRand::~MyRand() {
delete distribution;
}
// uniform distribution
// report a double between minValue and maxValue
double MyRand::runif(double minValue, double maxValue) {
#ifdef USE_BOOST
uniform_real<> unif(minValue,maxValue);
#else
uniform_real_distribution<double> unif(minValue,maxValue);
#endif
return unif(generator);
}
// uniform distribution between 0.0 and 1.0
double MyRand::runif() {
return distribution->operator()(generator);
}
// report an integer
int MyRand::iunif(int minValue, int maxValue) {
if (minValue == maxValue)
return minValue;
#ifdef USE_BOOST
uniform_int<> unii(minValue,maxValue);
#else
uniform_int_distribution<double> unii(minValue,maxValue);
#endif
return unii(generator);
}