-
Notifications
You must be signed in to change notification settings - Fork 1
/
Random.h
59 lines (49 loc) · 1.32 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <memory>
#include <random>
#ifndef __RANDOM_H__
#define __RANDOM_H__
namespace typing
{
class Random
{
public:
void Seed (unsigned int seed)
{
m_rng.seed(seed);
}
int Range (int min, int max)
{
if (min == max) {
return (max);
} else {
std::uniform_int_distribution<int> range(min, max);
return range(m_rng);
}
}
unsigned int Range (unsigned int min, unsigned int max)
{
return Range(static_cast<int>(min), static_cast<int>(max));
}
float Range (float min, float max)
{
return (static_cast<float>(Range(static_cast<double>(min), static_cast<double>(max))));
}
double Range (double min, double max)
{
if (min == max) {
return (max);
} else {
std::uniform_real_distribution<double> range(min, max);
return range(m_rng);
}
}
// Singleton implementation
static Random& GetRandom();
private:
std::mt19937 m_rng;
// Singleton implementation
static std::auto_ptr<Random> m_singleton;
};
#define RAND Random::GetRandom()
}
#endif /* __RANDOM_H__ */