-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.cpp
51 lines (43 loc) · 1.25 KB
/
random.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
#include "random.h"
#include <random>
#include <chrono>
#include <iostream>
// TODO: This should not be a class anymore but pure module (just set of functions + state)
class RandomGenerator {
public:
RandomGenerator() {
//displaySeed();
}
// RandomGenerator(int seed): seed{seed} {
// //displaySeed();
// }
void displaySeed() {
std::cout << "Seed: " << this->seed << '\n';
}
float get1() {
return distribution1(generator);
}
float get01() {
return distribution01(generator);
}
int get_int(int i) {
return dist_int(generator) % i;
}
private:
const int seed = std::chrono::system_clock::now().time_since_epoch().count();
//const long seed = 0; // Seed for testing
std::default_random_engine generator;
//static std::uniform_real_distribution<double> distribution05(-0.5f, 0.5f);
std::uniform_real_distribution<float> distribution1{-1.0, 1.0};
std::uniform_real_distribution<float> distribution01{0.0, 1.0};
std::uniform_int_distribution<int> dist_int{0, 1000000}; // TODO: find something better
};
namespace randomns {
thread_local RandomGenerator rnd;
float get1() {
return rnd.get1();
}
float get01() {
return rnd.get01();
}
} // namespace: random