mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 05:09:20 +02:00
use random_device for local generator
This commit is contained in:
@@ -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())
|
||||
{
|
||||
|
||||
@@ -16,7 +16,6 @@ Copyright (C) 2007-2014 Maciej Cierniak
|
||||
//#include <sys/types.h>
|
||||
//#include <sys/stat.h>
|
||||
#include <charconv>
|
||||
#include <ctime>
|
||||
#include <ranges>
|
||||
//#ifndef WIN32
|
||||
//#include <unistd.h>
|
||||
@@ -138,12 +137,6 @@ int Random(int min, int max)
|
||||
return dist(Global.random_engine);
|
||||
}
|
||||
|
||||
std::uint32_t clock_seed()
|
||||
{
|
||||
static std::atomic<std::uint32_t> nth{0};
|
||||
return static_cast<std::uint32_t>(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<int> dist(0, 255);
|
||||
|
||||
std::array<uint8_t, 16> bytes;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user