#define SIMGRID_XBT_RANDOM_HPP
#include "xbt/base.h"
+#include <fstream>
+#include <iostream>
#include <random>
+#include <string>
namespace simgrid {
namespace xbt {
/** @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;
*/
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)
*
class XBT_PUBLIC StdRandom : public Random {
public:
StdRandom() = default;
- StdRandom(int seed) : Random(seed) {}
+ explicit StdRandom(int seed) : Random(seed) {}
int uniform_int(int min, int max) override;
double uniform_real(double min, double max) override;
class XBT_PUBLIC XbtRandom : public Random {
public:
XbtRandom() = default;
- XbtRandom(int seed) : Random(seed) {}
+ explicit XbtRandom(int seed) : Random(seed) {}
int uniform_int(int min, int max) override;
double uniform_real(double min, double max) override;
*/
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)
*