uuid_v4 icon indicating copy to clipboard operation
uuid_v4 copied to clipboard

Is this library able to ensure that UUID_v4 does not conflict?

Open nolongerwait opened this issue 2 years ago • 4 comments

I used this library to generate uuid but found two cases of uuid conflict today. The two uuids I generated on December 1st conflicted with the two uuids on November 18th and 20th.

nolongerwait avatar Dec 02 '22 04:12 nolongerwait

Fine, I've had the same uuid generated twice on the same day in 4 months. This probability can no longer meet the requirements of uuid.

nolongerwait avatar Feb 23 '23 17:02 nolongerwait

I think that depends on the random number generator that you supply. The default isn't necessarily the best, but it does the job most of the time.

Though looking at the source code, it uses random_device, which should be 'true random' https://en.cppreference.com/w/cpp/numeric/random/random_device

When you got that collision, how did you compare? Was it with a hash?

duckdoom5 avatar Jul 17 '23 09:07 duckdoom5

UUIDv4::UUIDGenerator<std::mt19937_64> uuidGenerator;
UUIDv4::UUID uuid = uuidGenerator.getUUID();

nolongerwait avatar Jul 25 '23 10:07 nolongerwait

std::mt19937_64 is a pseudo random number generator that needs to be sourced with a random number (seed) before it can give you somewhat random numbers.

If you want it to be uuid v4 spec, you need to use std::random_device (which is the default if you don't supply a random engine)

duckdoom5 avatar Jul 25 '23 11:07 duckdoom5