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

namespace ur {

Random::Random(int min, int 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
  auto 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));
}

}