Browse Source

random prob generator for rationals

tempestpy_adaptions
Sebastian Junges 4 years ago
parent
commit
b7ad55b34b
  1. 24
      src/storm/utility/random.cpp
  2. 15
      src/storm/utility/random.h

24
src/storm/utility/random.cpp

@ -1,5 +1,7 @@
#include "storm/utility/random.h"
#include <limits>
namespace storm {
namespace utility {
RandomProbabilityGenerator<double>::RandomProbabilityGenerator()
@ -23,6 +25,28 @@ namespace storm {
return std::uniform_int_distribution<uint64_t>(min, max)(engine);
}
RandomProbabilityGenerator<RationalNumber>::RandomProbabilityGenerator()
: distribution(0, std::numeric_limits<uint64_t>::max())
{
std::random_device rd;
engine = std::mt19937(rd());
}
RandomProbabilityGenerator<RationalNumber>::RandomProbabilityGenerator(uint64_t seed)
: distribution(0, std::numeric_limits<uint64_t>::max()), engine(seed)
{
}
RationalNumber RandomProbabilityGenerator<RationalNumber>::random() {
return carl::rationalize<RationalNumber>(distribution(engine)) / carl::rationalize<RationalNumber>(std::numeric_limits<uint64_t>::max());
}
uint64_t RandomProbabilityGenerator<RationalNumber>::random_uint(uint64_t min, uint64_t max) {
return std::uniform_int_distribution<uint64_t>(min, max)(engine);
}
}
}

15
src/storm/utility/random.h

@ -1,4 +1,5 @@
#include <random>
#include "storm/adapters/RationalNumberAdapter.h"
namespace storm {
namespace utility {
@ -26,6 +27,20 @@ namespace storm {
};
template<>
class RandomProbabilityGenerator<storm::RationalNumber> {
public:
RandomProbabilityGenerator();
RandomProbabilityGenerator(uint64_t seed);
RationalNumber random();
uint64_t random_uint(uint64_t min, uint64_t max);
private:
std::uniform_int_distribution<uint64_t> distribution;
std::mt19937 engine;
};
}
}
Loading…
Cancel
Save