X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0f14a8aa6fecc78bf48d772d3a5cb123a5f7ce4f..e71a2a302d28430dc1bfee906f842f5f3d0fa3ce:/include/xbt/random.hpp diff --git a/include/xbt/random.hpp b/include/xbt/random.hpp index 8175c69ac5..8510d35959 100644 --- a/include/xbt/random.hpp +++ b/include/xbt/random.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -7,7 +7,10 @@ #define SIMGRID_XBT_RANDOM_HPP #include "xbt/base.h" +#include +#include #include +#include namespace simgrid { namespace xbt { @@ -25,7 +28,7 @@ public: /** @brief Build a new random number generator with default seed */ Random() = default; /** @brief Build a new random number generator with given seed */ - Random(int seed) : mt19937_gen(seed) {} + explicit Random(int seed) : mt19937_gen(seed) {} virtual ~Random() = default; @@ -34,6 +37,16 @@ public: */ void set_seed(int seed) { mt19937_gen.seed(seed); } + /** + * @brief Read the state of the Mersenne-Twister RNG from a file + */ + bool read_state(const std::string& filename); + + /** + * @brief Write the state of the Mersenne-Twister RNG to a file + */ + bool write_state(const std::string& filename) const; + /** * @brief Draws an integer number uniformly in range [min, max] (min and max included) * @@ -72,8 +85,7 @@ public: */ class XBT_PUBLIC StdRandom : public Random { public: - StdRandom() = default; - StdRandom(int seed) : Random(seed) {} + using Random::Random; int uniform_int(int min, int max) override; double uniform_real(double min, double max) override; @@ -87,8 +99,7 @@ public: */ class XBT_PUBLIC XbtRandom : public Random { public: - XbtRandom() = default; - XbtRandom(int seed) : Random(seed) {} + using Random::Random; int uniform_int(int min, int max) override; double uniform_real(double min, double max) override; @@ -111,6 +122,16 @@ void set_implem_std(); */ void set_mersenne_seed(int); +/** + * @brief Read the state of the Mersenne-Twister RNG from a file. + */ +bool read_mersenne_state(const std::string& filename); + +/** + * @brief Write the state of the Mersenne-Twister RNG to a file. + */ +bool write_mersenne_state(const std::string& filename); + /** * @brief Draws an integer number uniformly in range [min, max] (min and max included) *