mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 21:51:40 +03:00
Fix Issue 19138 - std.uuid.randomUUID should not depend on std.random.Random being Mt19937
This commit is contained in:
parent
9e1870c053
commit
202a837b7d
1 changed files with 19 additions and 13 deletions
32
std/uuid.d
32
std/uuid.d
|
@ -1210,7 +1210,25 @@ public struct UUID
|
||||||
@safe UUID randomUUID()
|
@safe UUID randomUUID()
|
||||||
{
|
{
|
||||||
import std.random : rndGen;
|
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
|
/// ditto
|
||||||
|
@ -1260,18 +1278,6 @@ if (isInputRange!RNG && isIntegral!(ElementType!RNG))
|
||||||
auto uuid3 = randomUUID(gen);
|
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
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.random : Xorshift192, unpredictableSeed;
|
import std.random : Xorshift192, unpredictableSeed;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue