-
Notifications
You must be signed in to change notification settings - Fork 4
/
Random.h
42 lines (33 loc) · 871 Bytes
/
Random.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
#ifndef RANDOM_H
#define RANDOM_H
#include <random>
#include <ctime>
template <typename Engine = std::mt19937>
class Random {
template<typename T>
using UniformDist = std::uniform_real_distribution<T>;
using UniformIntDist = std::uniform_int_distribution<int>;
public:
static Random gRand;
Random(int seed = std::time(nullptr))
: m_prng(seed) {
}
int getInt(int low, int high) {
return getNumberInRange<UniformIntDist>(low, high);
}
float getFloat(float low, float high) {
return getNumberInRange<UniformDist<float>>(low, high);
}
template<typename T>
T getNumberInRange(T low, T high) {
return getNumberInRange<UniformDist<T>>(low, high);
}
template<typename Dist, typename T>
T getNumberInRange(T low, T high) {
Dist dist(low, high);
return dist(m_prng);
}
private:
Engine m_prng;
};
#endif