diff options
author | Stephen Enders <smenders@gmail.com> | 2021-01-20 22:53:14 -0500 |
---|---|---|
committer | Stephen Enders <smenders@gmail.com> | 2021-01-21 20:56:16 -0500 |
commit | bb25b2bc17ca4cada09da38d209be57a55020d31 (patch) | |
tree | 04fbdaf27804dcf6991172e11ed44ae9b71eb4fe /random.cpp | |
parent | eccb6df404b9ae052b9d13750f54dc69241668b4 (diff) |
Add rolling animation
Diffstat (limited to 'random.cpp')
-rw-r--r-- | random.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/random.cpp b/random.cpp new file mode 100644 index 0000000..e94b191 --- /dev/null +++ b/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)); +} + +} |