mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 03:59:19 +02:00
use random_device for local generator
This commit is contained in:
@@ -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