diff options
author | Stephen Enders <smenders@gmail.com> | 2021-01-23 11:52:32 -0500 |
---|---|---|
committer | Stephen Enders <smenders@gmail.com> | 2021-01-23 11:52:32 -0500 |
commit | a408a43cd105b89a8d44292e2ef69802a5660497 (patch) | |
tree | a70ce8c54f57c2f6f2a8603b9e45d352cc5bc083 /src/random.cpp | |
parent | f01537a8ff454b68b83574f16cb4e2ff244a4e8a (diff) |
Move source files to src folder
We'll be making a few source files it'll be useful to have them
organized at least somewhat from our non-src files
Diffstat (limited to 'src/random.cpp')
-rw-r--r-- | src/random.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/random.cpp b/src/random.cpp new file mode 100644 index 0000000..e94b191 --- /dev/null +++ b/src/random.cpp @@ -0,0 +1,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)); +} + +} |