aboutsummaryrefslogtreecommitdiff
path: root/src/random.cc
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-03-29 20:39:19 +0200
committerAdrian Kummerlaender2016-03-29 20:39:19 +0200
commit26101aeb8ea28bd180b30fc67cba81baadbba8ee (patch)
tree33044ef62a61bbdd56f4d83b7dc59b7049431547 /src/random.cc
parent4e1a5ff8edfa09e74fc708521024fd359d96f7b0 (diff)
downloadjustify-26101aeb8ea28bd180b30fc67cba81baadbba8ee.tar
justify-26101aeb8ea28bd180b30fc67cba81baadbba8ee.tar.gz
justify-26101aeb8ea28bd180b30fc67cba81baadbba8ee.tar.bz2
justify-26101aeb8ea28bd180b30fc67cba81baadbba8ee.tar.lz
justify-26101aeb8ea28bd180b30fc67cba81baadbba8ee.tar.xz
justify-26101aeb8ea28bd180b30fc67cba81baadbba8ee.tar.zst
justify-26101aeb8ea28bd180b30fc67cba81baadbba8ee.zip
Move random index generation into utility class
Diffstat (limited to 'src/random.cc')
-rw-r--r--src/random.cc29
1 files changed, 29 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};
+}
+
+}