-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.hpp
More file actions
55 lines (44 loc) · 943 Bytes
/
Random.hpp
File metadata and controls
55 lines (44 loc) · 943 Bytes
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
#ifndef RANDOM_HPP
#define RANDOM_HPP
#include <chrono>
#include <random>
class Random
{
public:
std::mt19937_64 generator;
std::normal_distribution<double> normalDistribution;
std::uniform_real_distribution<double> uniformDistribution;
Random()
{
generator = std::mt19937_64(std::chrono::system_clock::now().time_since_epoch().count());
}
Random(int seed)
{
generator = std::mt19937_64(seed);
}
void UniformDistribution(double a, double b)
{
uniformDistribution = std::uniform_real_distribution<double>(a, b);
}
void UniformDistribution()
{
UniformDistribution(0.0, 1.0);
}
double NextDouble()
{
return uniformDistribution(generator);
}
void NormalDistribution(double mean, double std)
{
normalDistribution = std::normal_distribution<double>(mean, std);
}
void NormalDistribution()
{
NormalDistribution(0.0, 1.0);
}
double NextNormal()
{
return normalDistribution(generator);
}
};
#endif