From: Arnaud Giersch Date: Wed, 5 Feb 2020 22:45:20 +0000 (+0100) Subject: Replace usage of with . X-Git-Tag: v3.26~1011 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8e182ec667539e6e7459102565feded325aed259 Replace usage of with . --- diff --git a/examples/s4u/energy-link/s4u-energy-link.cpp b/examples/s4u/energy-link/s4u-energy-link.cpp index eb7d36ad71..cd0c5fbbc1 100644 --- a/examples/s4u/energy-link/s4u-energy-link.cpp +++ b/examples/s4u/energy-link/s4u-energy-link.cpp @@ -5,13 +5,12 @@ #include "simgrid/plugins/energy.h" #include "xbt/log.h" +#include "xbt/random.hpp" #include -#include - /* Parameters of the random generation of the flow size */ -static const unsigned long int min_size = 1e6; -static const unsigned long int max_size = 1e9; +static const int min_size = 1e6; +static const int max_size = 1e9; XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_energyconsumption, "Messages specific for this s4u example"); @@ -93,16 +92,8 @@ int main(int argc, char* argv[]) if (argc > 3) { if (strcmp(argv[3], "random") == 0) { // We're asked to get a random size - /* Initialize the random number generator */ - std::random_device rd; - std::default_random_engine generator(rd()); - - /* Distribution on which to apply the generator */ - std::uniform_int_distribution distribution(min_size, max_size); - - char* size = bprintf("%lu", distribution(generator)); - argSender.push_back(std::string(size)); - xbt_free(size); + std::string size = std::to_string(simgrid::xbt::random::uniform_int(min_size, max_size)); + argSender.push_back(size); } else { // Not "random" ? Then it should be the size to use argSender.push_back(argv[3]); // Take the datasize from the command line } diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 824af31f8b..963a71eb94 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -9,9 +9,9 @@ #include "src/surf/network_interface.hpp" #include "src/surf/surf_private.hpp" #include "surf/surf.hpp" +#include "xbt/random.hpp" #include #include -#include enum class InstrUserVariable { DECLARE, SET, ADD, SUB }; @@ -89,11 +89,9 @@ void TRACE_category_with_color (const char *category, const char *color) std::string final_color; if (not color) { //generate a random color - static std::default_random_engine rnd_engine; - std::uniform_real_distribution prng(0.0, std::nextafter(1.0, 2.0)); - double red = prng(rnd_engine); - double green = prng(rnd_engine); - double blue = prng(rnd_engine); + double red = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0)); + double green = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0)); + double blue = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0)); final_color = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue); }else{ final_color = std::string(color); diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index b76dc7c3af..3656982bf2 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -11,7 +11,7 @@ #include "src/mc/mc_replay.hpp" #include "src/simix/smx_private.hpp" -#include +#include "xbt/random.hpp" #if SIMGRID_HAVE_MC #include "src/mc/ModelChecker.hpp" @@ -166,9 +166,8 @@ bool request_is_visible(const s_smx_simcall* req) int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max) { if (not MC_is_active() && MC_record_path.empty()) { - static std::default_random_engine rnd_engine; - std::uniform_int_distribution prng(min, max); - return prng(rnd_engine); + static simgrid::xbt::random::XbtRandom prng; + return prng.uniform_int(min, max); } return simcall->mc_value_; } diff --git a/src/mc/sosp/Snapshot_test.cpp b/src/mc/sosp/Snapshot_test.cpp index 36a7298b5b..f78365f485 100644 --- a/src/mc/sosp/Snapshot_test.cpp +++ b/src/mc/sosp/Snapshot_test.cpp @@ -8,8 +8,8 @@ #include "src/mc/sosp/Snapshot.hpp" #include -#include #include +#include /**************** Class BOOST_tests *************************/ using simgrid::mc::Region; @@ -37,19 +37,17 @@ public: mc_model_checker = nullptr; } - static std::default_random_engine rnd_engine; static std::unique_ptr process; }; // static member variables init. -std::default_random_engine snap_test_helper::rnd_engine; std::unique_ptr snap_test_helper::process = nullptr; void snap_test_helper::init_memory(void* mem, size_t size) { char* dest = (char*)mem; for (size_t i = 0; i < size; ++i) { - dest[i] = rnd_engine() & 255; + dest[i] = simgrid::xbt::random::uniform_int(0, 0xff); } } @@ -111,8 +109,8 @@ void snap_test_helper::read_region_parts() prologue_return ret = prologue(n); for (int j = 0; j != 100; ++j) { - size_t offset = rnd_engine() % ret.size; - size_t size = rnd_engine() % (ret.size - offset); + size_t offset = simgrid::xbt::random::uniform_int(0, ret.size - 1); + size_t size = simgrid::xbt::random::uniform_int(0, ret.size - offset - 1); const void* read = ret.region->read(ret.dstn, (const char*)ret.src + offset, size); INFO("Mismatch in MC_region_read()"); REQUIRE(not memcmp((char*)ret.src + offset, read, size)); @@ -145,8 +143,8 @@ void snap_test_helper::compare_region_parts() prologue_return ret = prologue(n); for (int j = 0; j != 100; ++j) { - size_t offset = rnd_engine() % ret.size; - size_t size = rnd_engine() % (ret.size - offset); + size_t offset = simgrid::xbt::random::uniform_int(0, ret.size - 1); + size_t size = simgrid::xbt::random::uniform_int(0, ret.size - offset - 1); INFO("Mismatch in MC_snapshot_region_memcmp()"); REQUIRE(not MC_snapshot_region_memcmp((char*)ret.src + offset, ret.region, (char*)ret.src + offset, ret.region, diff --git a/src/xbt/dict_test.cpp b/src/xbt/dict_test.cpp index ed105ea6a8..58913944d9 100644 --- a/src/xbt/dict_test.cpp +++ b/src/xbt/dict_test.cpp @@ -8,9 +8,9 @@ #include "xbt/dict.h" #include "simgrid/Exception.hpp" +#include "xbt/random.hpp" #include #include -#include #include "catch.hpp" @@ -264,9 +264,6 @@ TEST_CASE("xbt::dict: dict data container", "dict") SECTION("Crash test") { - std::random_device rd; - std::default_random_engine rnd_engine(rd()); - for (int i = 0; i < 10; i++) { INFO("CRASH test number " << i + 1 << " (" << 10 - i - 1 << " to go)"); INFO("Fill the struct, count its elems and frees the structure"); @@ -278,7 +275,7 @@ TEST_CASE("xbt::dict: dict data container", "dict") do { for (int k = 0; k < SIZEOFKEY - 1; k++) { - key[k] = rnd_engine() % ('z' - 'a') + 'a'; + key[k] = simgrid::xbt::random::uniform_int('a', 'z'); } key[SIZEOFKEY - 1] = '\0'; data = (char*)xbt_dict_get_or_null(head, key); diff --git a/teshsuite/surf/wifi_usage/wifi_usage.cpp b/teshsuite/surf/wifi_usage/wifi_usage.cpp index d6929d6360..1d5e849bc3 100644 --- a/teshsuite/surf/wifi_usage/wifi_usage.cpp +++ b/teshsuite/surf/wifi_usage/wifi_usage.cpp @@ -8,10 +8,6 @@ #include "simgrid/msg.h" #include "src/surf/network_wifi.hpp" -#include -#include -#include -#include XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[usage] wifi_usage ");