diff --git a/util/random.cc b/util/random.cc index 37e88e19f..56944773f 100644 --- a/util/random.cc +++ b/util/random.cc @@ -6,9 +6,10 @@ #include "util/random.h" -#include #include #include +#include +#include #include "port/likely.h" #include "util/thread_local.h" @@ -27,10 +28,8 @@ Random* Random::GetTLSInstance() { auto rv = tls_instance; if (UNLIKELY(rv == nullptr)) { - const pthread_t self = pthread_self(); - uint32_t seed = 0; - memcpy(&seed, &self, sizeof(seed)); - rv = new (&tls_instance_bytes) Random(seed); + size_t seed = std::hash()(std::this_thread::get_id()); + rv = new (&tls_instance_bytes) Random((uint32_t)seed); tls_instance = rv; } return rv; diff --git a/util/random.h b/util/random.h index f259db07d..8f90c7675 100644 --- a/util/random.h +++ b/util/random.h @@ -18,8 +18,12 @@ namespace rocksdb { // package. class Random { private: - static constexpr uint32_t M = 2147483647L; // 2^31-1 - static constexpr uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 + enum : uint32_t { + M = 2147483647L // 2^31-1 + }; + enum : uint64_t { + A = 16807 // bits 14, 8, 7, 5, 2, 1, 0 + }; uint32_t seed_; @@ -27,7 +31,7 @@ class Random { public: // This is the largest value that can be returned from Next() - static constexpr uint32_t kMaxNext = M; + enum : uint32_t { kMaxNext = M }; explicit Random(uint32_t s) : seed_(GoodSeed(s)) {}