penguins  1.0.0
better_random.cc
Go to the documentation of this file.
1 #include "gui/better_random.hh"
2 #include <memory>
3 #include <random>
4 
6  // std::random_device has really large internal state, something like 5
7  // kilobytes (on GCC/Linux), therefore I think its better to allocate it on
8  // the heap.
9  std::unique_ptr<std::random_device> rng_dev(new std::random_device());
10  this->rng_engine.seed((*rng_dev)());
12 }
13 
14 int BetterRng::random_range_impl(Rng* rng, int min, int max) {
15  auto self = (BetterRng*)rng;
16  std::uniform_int_distribution<int> distribution(min, max);
17  return distribution(self->rng_engine);
18 }
An implementation of Rng for C++ using the standard functions from <random>.
BetterRng()
Seeds the rng_engine using std::random_device.
Definition: better_random.cc:5
std::default_random_engine rng_engine
static int random_range_impl(Rng *rng, int min, int max)
See Rng::random_range.
A wrapper around random number generators.
Definition: utils.h:129
int(* random_range)(struct Rng *self, int min, int max)
Generates and returns a value in the range [min; max) (i.e. from min inclusive to max exclusive).
Definition: utils.h:132