-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrand_gen.cc
41 lines (33 loc) · 1 KB
/
rand_gen.cc
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
#include "rand_gen.h"
rand_gen::rand_gen() {
// Generate the seed of rand gen
generator.seed(std::chrono::system_clock::now().time_since_epoch().count());
}
rand_gen::~rand_gen() {
}
int rand_gen::irand(int LO,int HI) {
srand(time(NULL)+rand());
return LO + rand()%(HI);
}
float rand_gen::frand(double LO,double HI) {
srand(time(NULL)+rand());
return LO + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(HI-LO)));
}
double rand_gen::exponential(double lambda) {
// specify upperbound and lowerbound
std::exponential_distribution<double> dist(lambda);
// return random value
return dist(generator);
}
int rand_gen::uniform_int(int lb,int ub){
// specify upperbound and lowerbound
std::uniform_int_distribution<int> dist(lb,ub);
// return random value
return dist(generator);
}
double rand_gen::uniform_real(double lb,double ub) {
// specify upperbound and lowerbound
std::uniform_real_distribution<double> dist(lb,ub);
// return random value
return dist(generator);
}