diff --git a/std/uuid.d b/std/uuid.d index 6f5a72d8b..825e53dfe 100644 --- a/std/uuid.d +++ b/std/uuid.d @@ -1210,7 +1210,25 @@ public struct UUID @safe UUID randomUUID() { import std.random : rndGen; - return randomUUID(rndGen); + // A PRNG with fewer than `n` bytes of state cannot produce + // every distinct `n` byte sequence. + static if (typeof(rndGen).sizeof >= UUID.sizeof) + { + return randomUUID(rndGen); + } + else + { + import std.random : unpredictableSeed, Xorshift192; + static assert(Xorshift192.sizeof >= UUID.sizeof); + static Xorshift192 rng; + static bool initialized; + if (!initialized) + { + rng.seed(unpredictableSeed); + initialized = true; + } + return randomUUID(rng); + } } /// ditto @@ -1260,18 +1278,6 @@ if (isInputRange!RNG && isIntegral!(ElementType!RNG)) auto uuid3 = randomUUID(gen); } -/* - * Original boost.uuid used Mt19937, we don't want - * to use anything worse than that. If Random is changed - * to something else, this assert and the randomUUID function - * have to be updated. - */ -@safe unittest -{ - import std.random : rndGen, Mt19937; - static assert(is(typeof(rndGen) == Mt19937)); -} - @safe unittest { import std.random : Xorshift192, unpredictableSeed;