[ox/std] Shift away 4 lowest bits of random numbers generated in UUID,

as Xoroshiro128+ is apparently weaker for those bits
This commit is contained in:
Gary Talent 2023-03-03 00:57:25 -06:00
parent b576a7ec12
commit 06f6656c85

View File

@ -25,7 +25,9 @@ Result<UUID> UUID::generate() noexcept {
}
UUID out;
for (auto &v : out.m_value) {
v = static_cast<uint8_t>(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<uint8_t>(rand % 255);
}
out.m_value[6] &= 0x0f;
out.m_value[6] |= 4 << 4;