#include "simgrid/plugins/energy.h"
#include "xbt/log.h"
+#include "xbt/random.hpp"
#include <simgrid/s4u.hpp>
-#include <random>
-
/* 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");
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<unsigned long int> 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
}
#include "src/surf/network_interface.hpp"
#include "src/surf/surf_private.hpp"
#include "surf/surf.hpp"
+#include "xbt/random.hpp"
#include <algorithm>
#include <cmath>
-#include <random>
enum class InstrUserVariable { DECLARE, SET, ADD, SUB };
std::string final_color;
if (not color) {
//generate a random color
- static std::default_random_engine rnd_engine;
- std::uniform_real_distribution<double> 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);
#include "src/mc/mc_replay.hpp"
#include "src/simix/smx_private.hpp"
-#include <random>
+#include "xbt/random.hpp"
#if SIMGRID_HAVE_MC
#include "src/mc/ModelChecker.hpp"
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<int> prng(min, max);
- return prng(rnd_engine);
+ static simgrid::xbt::random::XbtRandom prng;
+ return prng.uniform_int(min, max);
}
return simcall->mc_value_;
}
#include "src/mc/sosp/Snapshot.hpp"
#include <cstddef>
-#include <random>
#include <sys/mman.h>
+#include <xbt/random.hpp>
/**************** Class BOOST_tests *************************/
using simgrid::mc::Region;
mc_model_checker = nullptr;
}
- static std::default_random_engine rnd_engine;
static std::unique_ptr<simgrid::mc::RemoteClient> process;
};
// static member variables init.
-std::default_random_engine snap_test_helper::rnd_engine;
std::unique_ptr<simgrid::mc::RemoteClient> 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);
}
}
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));
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,
#include "xbt/dict.h"
#include "simgrid/Exception.hpp"
+#include "xbt/random.hpp"
#include <cstdio>
#include <cstring>
-#include <random>
#include "catch.hpp"
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");
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);
#include "simgrid/msg.h"
#include "src/surf/network_wifi.hpp"
-#include <exception>
-#include <iostream>
-#include <random>
-#include <string>
XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[usage] wifi_usage <platform-file>");