diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/random.cc | 29 | ||||
-rw-r--r-- | src/random.h | 34 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/random.cc b/src/random.cc new file mode 100644 index 0000000..dba3647 --- /dev/null +++ b/src/random.cc @@ -0,0 +1,29 @@ +#include "random.h" + +namespace utility { + +std::size_t Random::Range::get() { + return this->distribution_(*(this->generator_)); +} + +Random::Range::Range( + std::mt19937* const generator, + const std::size_t a, + const std::size_t b +): + generator_(generator), + distribution_(a, b) { } + +Random::Random(): + device_{}, + generator_{device_()} { } + +Random::Range Random::makeRange( + const std::size_t a, + const std::size_t b) { + this->generator_.seed(this->device_()); + + return Range{&(this->generator_), a, b}; +} + +} diff --git a/src/random.h b/src/random.h new file mode 100644 index 0000000..386dc21 --- /dev/null +++ b/src/random.h @@ -0,0 +1,34 @@ +#pragma once + +#include <random> + +namespace utility { + +class Random { + public: + class Range { + public: + std::size_t get(); + + protected: + friend class Random; + + Range(std::mt19937* const, const std::size_t, const std::size_t); + + private: + std::mt19937* const generator_; + std::uniform_int_distribution<std::size_t> distribution_; + }; + + Random(); + + Range makeRange(const std::size_t, const std::size_t); + + private: + std::random_device device_; + std::mt19937 generator_; + +}; + + +} |