19#include <nlohmann/json.hpp>
20using json = nlohmann::json;
48 uint64_t
seed =
useSeed ? this->
seed :
static_cast<uint64_t
>(std::chrono::system_clock::now().time_since_epoch().count());
49 auto hash = hashSeed(std::to_string(
seed) + (
useSeed ||
id == 0 ?
"" :
" " + std::to_string(
id)));
50 std::seed_seq seed_seq(hash.begin(), hash.end());
51 _generator.seed(seed_seq);
58 auto hash = hashSeed(std::to_string(userSeed));
59 std::seed_seq seed_seq(hash.begin(), hash.end());
60 _generator.seed(seed_seq);
68 template<
typename IntType =
int>
71 return std::uniform_int_distribution<IntType>(min, max)(_generator);
79 template<
typename RealType =
double>
82 return std::uniform_real_distribution<RealType>(min, max)(_generator);
90 template<
typename RealType =
double>
93 return std::normal_distribution<RealType>(mean, stddev)(_generator);
103 static std::string hashSeed(
const std::string&
seed)
107 uint8_t* digest = sha.digest();
109 std::string hashed(digest, digest + 32);
115 std::mt19937_64 _generator;
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
Manages a thread which calls a specified function at a specified interval.
Definition RandomNumberGenerator.hpp:29
RandomNumberGenerator(bool useSeed=true)
Default constructor.
Definition RandomNumberGenerator.hpp:32
RandomNumberGenerator & operator=(const RandomNumberGenerator &)=delete
Copy assignment operator.
uint64_t seed
Seed for the random number generator.
Definition RandomNumberGenerator.hpp:97
double getRand_uniformIntDist(IntType min=0, IntType max=std::numeric_limits< IntType >::max())
Gets a random integer number from an uniform distribution.
Definition RandomNumberGenerator.hpp:69
bool useSeed
Flag whether to use the seed instead of the system time.
Definition RandomNumberGenerator.hpp:96
double getRand_uniformRealDist(RealType min=0.0, RealType max=1.0)
Gets a random real number from an uniform distribution.
Definition RandomNumberGenerator.hpp:80
double getRand_normalDist(RealType mean=0.0, RealType stddev=1.0)
Gets a random number from a normal distribution.
Definition RandomNumberGenerator.hpp:91
~RandomNumberGenerator()=default
Destructor.
RandomNumberGenerator(const RandomNumberGenerator &)=delete
Copy constructor.
void resetSeed(size_t id=0)
Reset the seed to the internal seed or the system time.
Definition RandomNumberGenerator.hpp:46
RandomNumberGenerator(RandomNumberGenerator &&)=delete
Move constructor.
RandomNumberGenerator & operator=(RandomNumberGenerator &&)=delete
Move assignment operator.
void resetSeedOnce(uint64_t userSeed)
Reset the seed to the specified seed, but do not update the internal seed.
Definition RandomNumberGenerator.hpp:56