From b7ad55b34b9bfff8ec9e9d47faad0303d8279bef Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Wed, 30 Sep 2020 20:31:54 -0700 Subject: [PATCH] random prob generator for rationals --- src/storm/utility/random.cpp | 24 ++++++++++++++++++++++++ src/storm/utility/random.h | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/storm/utility/random.cpp b/src/storm/utility/random.cpp index f13d403cd..9e2d0ae35 100644 --- a/src/storm/utility/random.cpp +++ b/src/storm/utility/random.cpp @@ -1,5 +1,7 @@ #include "storm/utility/random.h" +#include + namespace storm { namespace utility { RandomProbabilityGenerator::RandomProbabilityGenerator() @@ -23,6 +25,28 @@ namespace storm { return std::uniform_int_distribution(min, max)(engine); } + RandomProbabilityGenerator::RandomProbabilityGenerator() + : distribution(0, std::numeric_limits::max()) + { + std::random_device rd; + engine = std::mt19937(rd()); + } + + RandomProbabilityGenerator::RandomProbabilityGenerator(uint64_t seed) + : distribution(0, std::numeric_limits::max()), engine(seed) + { + + } + + RationalNumber RandomProbabilityGenerator::random() { + return carl::rationalize(distribution(engine)) / carl::rationalize(std::numeric_limits::max()); + + } + + uint64_t RandomProbabilityGenerator::random_uint(uint64_t min, uint64_t max) { + return std::uniform_int_distribution(min, max)(engine); + } + } } diff --git a/src/storm/utility/random.h b/src/storm/utility/random.h index 93bfad20c..7e6e015be 100644 --- a/src/storm/utility/random.h +++ b/src/storm/utility/random.h @@ -1,4 +1,5 @@ #include +#include "storm/adapters/RationalNumberAdapter.h" namespace storm { namespace utility { @@ -26,6 +27,20 @@ namespace storm { }; + template<> + class RandomProbabilityGenerator { + public: + RandomProbabilityGenerator(); + RandomProbabilityGenerator(uint64_t seed); + RationalNumber random(); + uint64_t random_uint(uint64_t min, uint64_t max); + private: + std::uniform_int_distribution distribution; + std::mt19937 engine; + + }; + + } } \ No newline at end of file