From: Arnaud Giersch Date: Fri, 1 Mar 2019 22:16:49 +0000 (+0100) Subject: Use C++11 for simcall mc_random. X-Git-Tag: v3_22~187 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9e1c4c41d5e7fbdecae863782f410a1d1b0afc00 Use C++11 for simcall mc_random. --- diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index 83a39e4bbe..299dbdedcd 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -13,6 +13,8 @@ #include "src/mc/mc_replay.hpp" #include "src/simix/smx_private.hpp" +#include + #if SIMGRID_HAVE_MC #include "src/mc/ModelChecker.hpp" #include "src/mc/remote/RemoteClient.hpp" @@ -160,28 +162,12 @@ bool request_is_visible(smx_simcall_t req) } } -static int prng_random(int min, int max) -{ - unsigned long output_size = ((unsigned long) max - (unsigned long) min) + 1; - unsigned long input_size = (unsigned long) RAND_MAX + 1; - unsigned long reject_size = input_size % output_size; - unsigned long accept_size = input_size - reject_size; // module*accept_size - - // Use rejection in order to avoid skew - unsigned long x; - do { -#ifndef _WIN32 - x = (unsigned long) random(); -#else - x = (unsigned long) rand(); -#endif - } while( x >= accept_size ); - return min + (x % output_size); -} - int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max) { - if (not MC_is_active() && MC_record_path.empty()) - return prng_random(min, 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); + } return simcall->mc_value; }