Thrive
rng.h
1 #pragma once
2 
3 #include <algorithm>
4 #include <memory>
5 #include <random>
6 
7 
8 namespace luabind {
9 class scope;
10 }
11 
12 namespace thrive {
13 
19 class RNG final {
20 
21 public:
22 
26  using Seed = unsigned int; // parts of <random> uses unsigned int
27 
39  static luabind::scope
40  luaBindings();
41 
45  RNG();
46 
53  RNG(Seed seed);
54 
58  ~RNG();
59 
66  void
67  setSeed(Seed seed);
68 
75  Seed
76  getSeed() const;
77 
78 
85  Seed
87 
94  double
95  getDouble(
96  double min,
97  double max
98  );
99 
106  int
107  getInt(
108  int min,
109  int max
110  );
111 
121  template<typename iterType>
122  void
124  iterType first,
125  iterType last
126  ) {
127  std::shuffle(first, last, mersenneTwister());
128  }
129 
130 
131 private:
132 
133  std::mt19937&
134  mersenneTwister();
135 
136  struct Implementation;
137  std::unique_ptr<Implementation> m_impl;
138 
139 };
140 
141 }
Random Number Generator.
Definition: rng.h:19
unsigned int Seed
Typedef for seed values.
Definition: rng.h:26
RNG()
Constructor using proper random seed.
Definition: rng.cpp:41
~RNG()
Destructor.
Definition: rng.cpp:54
void setSeed(Seed seed)
Restarts the RNG with provided seed.
Definition: rng.cpp:58
Seed generateRandomSeed()
Generates a proper random seed.
Definition: rng.cpp:73
double getDouble(double min, double max)
Generates a random double between min and max.
Definition: rng.cpp:79
Definition: bullet_to_ogre_system.h:5
void shuffle(iterType first, iterType last)
Shuffles iterable collection.
Definition: rng.h:123
Definition: bullet_ogre_conversion.h:6
int getInt(int min, int max)
Generates a random integer between min and max.
Definition: rng.cpp:89
static luabind::scope luaBindings()
Lua bindings.
Definition: rng.cpp:30
Seed getSeed() const
Returns the current seed.
Definition: rng.cpp:67