X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d2182f07ffae5d26030b8f05cb2f3eb845c5bb4d..b570efb92a5785e2283c9116869e8773e03a3f81:/include/xbt/random.hpp?ds=sidebyside diff --git a/include/xbt/random.hpp b/include/xbt/random.hpp index 83c8cbf240..35d2809469 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-2022. 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. */ @@ -40,20 +40,12 @@ public: /** * @brief Read the state of the Mersenne-Twister RNG from a file */ - void read_state(std::string filename) - { - std::ifstream file(filename); - file >> mt19937_gen; - } + bool read_state(const std::string& filename); /** * @brief Write the state of the Mersenne-Twister RNG to a file */ - void write_state(std::string filename) - { - std::ofstream file(filename); - file << mt19937_gen; - } + bool write_state(const std::string& filename) const; /** * @brief Draws an integer number uniformly in range [min, max] (min and max included) @@ -93,8 +85,7 @@ public: */ class XBT_PUBLIC StdRandom : public Random { public: - StdRandom() = default; - explicit StdRandom(int seed) : Random(seed) {} + using Random::Random; int uniform_int(int min, int max) override; double uniform_real(double min, double max) override; @@ -108,8 +99,7 @@ public: */ class XBT_PUBLIC XbtRandom : public Random { public: - XbtRandom() = default; - explicit XbtRandom(int seed) : Random(seed) {} + using Random::Random; int uniform_int(int min, int max) override; double uniform_real(double min, double max) override; @@ -133,14 +123,14 @@ void set_implem_std(); void set_mersenne_seed(int); /** - * @brief Read the state of the Mersenne-Twister RNG from a file + * @brief Read the state of the Mersenne-Twister RNG from a file. */ -void read_mersenne_state(std::string filename); +bool read_mersenne_state(const std::string& filename); /** - * @brief Write the state of the Mersenne-Twister RNG to a file + * @brief Write the state of the Mersenne-Twister RNG to a file. */ -void write_mersenne_state(std::string filename); +bool write_mersenne_state(const std::string& filename); /** * @brief Draws an integer number uniformly in range [min, max] (min and max included)