diff --git a/include/cln/random.h b/include/cln/random.h index 6ef2610..06604e2 100644 --- a/include/cln/random.h +++ b/include/cln/random.h @@ -33,7 +33,15 @@ inline uint64 random64 (random_state& randomstate) // Ein globaler Zufallszahlengenerator. extern random_state default_random_state; -CL_REQUIRE(cl_random_def) +class cl_random_def_init_helper +{ + static int count; +public: + cl_random_def_init_helper(); + ~cl_random_def_init_helper(); +}; +static cl_random_def_init_helper cl_random_def_init_helper_instance; + // Das ist der Default-Generator. inline uint32 random32 (void) { return random32(default_random_state); } diff --git a/src/base/random/cl_random_def.cc b/src/base/random/cl_random_def.cc index 59373a6..9728273 100644 --- a/src/base/random/cl_random_def.cc +++ b/src/base/random/cl_random_def.cc @@ -3,8 +3,6 @@ // General includes. #include "cl_sysdep.h" -CL_PROVIDE(cl_random_def) - // Specification. #include "cln/random.h" @@ -15,6 +13,20 @@ namespace cln { random_state default_random_state; +int cl_random_def_init_helper::count = 0; +cl_random_def_init_helper::cl_random_def_init_helper() +{ + if (count++ == 0) { + default_random_state = random_state(); + } +} + +cl_random_def_init_helper::~cl_random_def_init_helper() +{ + if (--count == 0) { + // Nothing to clean up? + } +} + } // namespace cln -CL_PROVIDE_END(cl_random_def)