17 #include "mt19937_rng.h"
20 #include <unordered_map>
24 std::mt19937_64 global;
25 std::unordered_map<void*, std::mt19937_64> inst;
26 uint64_t seed{std::mt19937_64::default_seed};
30 bool debug_randomization = getenv(
"SCC_DEBUG_RANDOMIZATION") !=
nullptr;
33 auto scc::MT19937::inst() -> std::mt19937_64& {
35 if(
auto* obj = sc_core::sc_get_current_object()) {
36 auto sz = rng.inst.size();
37 auto& ret = rng.inst[obj];
38 if(rng.inst.size() > sz) {
41 seed =
reinterpret_cast<uintptr_t
>(&rng.inst) ^ rng.seed;
42 if(debug_randomization)
43 std::cout <<
"seeding rng for " << obj->name() <<
" with global seed " << seed <<
"\n";
45 std::string name{obj->name()};
46 std::hash<std::string> h;
47 seed = (h(name) ^ rng.seed);
48 if(debug_randomization)
49 std::cout <<
"seeding rng for " << obj->name() <<
" with local seed " << seed <<
"\n";
53 if(debug_randomization) {
54 std::cout <<
"retrieving next rnd number for " << obj->name() <<
"\n";
64 rng.global.seed(new_seed);
65 for(
auto& e : rng.inst)
66 e.second.seed(new_seed);
static void enable_global_seed(bool enable)
static void seed(uint64_t new_seed=std::mt19937_64::default_seed)