diff --git a/application/application.cpp b/application/application.cpp index 49d493c2..718380c7 100644 --- a/application/application.cpp +++ b/application/application.cpp @@ -320,9 +320,11 @@ int eu07_application::init(int Argc, char *Argv[]) return result; } + // the run's seed, settled once and kept in Globals: the engines come out of it if (!Global.random_seed) - Global.random_seed = clock_seed(); + Global.random_seed = std::random_device{}(); Global.random_engine.seed(Global.random_seed); + Global.local_random_engine.seed(Global.random_seed); // configure the OS console according to Globals.ShowSystemConsole. // must run AFTER init_settings (so the ini-loaded value is honoured) and @@ -1432,7 +1434,6 @@ int eu07_application::init_data() int eu07_application::init_modes() { - Global.local_random_engine.seed(clock_seed()); if ((!Global.network_servers.empty() || Global.network_client) && Global.SceneryFile.empty()) { diff --git a/utilities/utilities.cpp b/utilities/utilities.cpp index 1f5f0682..92aa28ed 100644 --- a/utilities/utilities.cpp +++ b/utilities/utilities.cpp @@ -16,7 +16,6 @@ Copyright (C) 2007-2014 Maciej Cierniak //#include //#include #include -#include #include //#ifndef WIN32 //#include @@ -138,12 +137,6 @@ int Random(int min, int max) return dist(Global.random_engine); } -std::uint32_t clock_seed() -{ - static std::atomic nth{0}; - return static_cast(std::time({})) + nth.fetch_add(1, std::memory_order_relaxed); -} - std::uint32_t seed_of(std::string const &Text) { std::uint32_t number{}; @@ -161,7 +154,7 @@ std::uint32_t seed_of(std::string const &Text) std::string generate_uuid_v4() { - static thread_local std::mt19937 generator{clock_seed()}; + static thread_local std::mt19937 generator{std::random_device{}()}; std::uniform_int_distribution dist(0, 255); std::array bytes; diff --git a/utilities/utilities.h b/utilities/utilities.h index d013fade..f90bd896 100644 --- a/utilities/utilities.h +++ b/utilities/utilities.h @@ -63,10 +63,6 @@ inline long Round(double const f) double Random(double a, double b); int Random(int min, int max); -// Seed for the random engines: the clock, plus a counter so two engines seeded in -// the same second do not come out the same. -std::uint32_t clock_seed(); - // The seed a word stands for. A number is taken as it is written; anything else is // hashed the way Java's String.hashCode does it, so the same word gives the same // world on every platform and every build - which is the whole point of telling diff --git a/utilities/uuid.hpp b/utilities/uuid.hpp index ff32f5d2..3326ecf1 100644 --- a/utilities/uuid.hpp +++ b/utilities/uuid.hpp @@ -14,7 +14,7 @@ public: static UID random() { - static thread_local std::mt19937_64 gen{clock_seed()}; + static thread_local std::mt19937_64 gen{std::random_device{}()}; UID u; uint64_t a = gen(); uint64_t b = gen();