Fix Issue 19836 - Excessive probability of UUID collisions in std.uuid.randomUUID #6985
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On 64-bit architectures use 64 bits of entropy to initialize thread-local
rndGen
.The motivation for this change is std.uuid defaults to using
rndGen
to generate UUIDs. If everyrndGen
starts in one of 2^^32 states then if 77000 independent programs each generate a single UUID there is a 50% chance that at least two of them generate the same initial UUID (and all subsequent UUIDs would be identical as well). Not just Phobos but also C++boost::uuids::random_generator
defaults to generating UUIDs with a Mersenne Twister initialized from a 32-bit seed, exacerbating the collision problem further. If instead there are 2^^64 possible initial states ofrndGen
there can be over 5 billion independentrndGen
s before there is a 50% chance of two having identical initial states.This change is limited to 64-bit architectures to avoid a measurable performance decrease, because many programs are not generating UUIDs.