From 06f6656c850e963b0b43094a0da88c3e1a37a34a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 3 Mar 2023 00:57:25 -0600 Subject: [PATCH] [ox/std] Shift away 4 lowest bits of random numbers generated in UUID, as Xoroshiro128+ is apparently weaker for those bits --- deps/ox/src/ox/std/uuid.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deps/ox/src/ox/std/uuid.cpp b/deps/ox/src/ox/std/uuid.cpp index df080d997..89f5be52f 100644 --- a/deps/ox/src/ox/std/uuid.cpp +++ b/deps/ox/src/ox/std/uuid.cpp @@ -25,7 +25,9 @@ Result UUID::generate() noexcept { } UUID out; for (auto &v : out.m_value) { - v = static_cast(s_rand.gen() % 255); + // shift away 4 lowest bits, as Xoroshiro128+ randomness is weaker there + const auto rand = s_rand.gen() >> 4; + v = static_cast(rand % 255); } out.m_value[6] &= 0x0f; out.m_value[6] |= 4 << 4;