Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nolongerwait opened this issue Dec 2, 2022 · 4 comments
Open

Comments

@nolongerwait
Copy link

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
Copy link
Author

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.

@duckdoom5
Copy link
Contributor

duckdoom5 commented Jul 17, 2023

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?

@nolongerwait
Copy link
Author

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

@duckdoom5
Copy link
Contributor

duckdoom5 commented Jul 25, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants