summaryrefslogtreecommitdiff
path: root/src/random.cpp
blob: e94b191296b1009c3f5f5fcc7ca143d065a299c7 (plain)
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
#include "random.hpp"
#include <chrono>
#include <cmath>

namespace ur {

Random::Random(int min, int max)
{
  this->min = min;
  this->max = max;
  // setup the random stuff
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
  this->engine = std::default_random_engine(seed);

  // setup distribution
  float range = float(max - min);
  this->distribution =
    std::normal_distribution<float>(range / 2.f, range / 4.f);
}

int
Random::next()
{
  return std::round(this->distribution(this->engine));
}

}