-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
change uuid to use Random.RandomDevice() instead of Random.default_rng() #35872
Conversation
Looks good to me. A simple test that could be done after this is setting the global RNG seed to the same value twice and generating a new UUID by each of these methods after and checking that they are not the same. Before this, that would have failed, so that's a good regression test. |
Also, this needs docs and news. And maybe a "!!! compat" annotation saying that this new behavior starts in version 1.6. |
This may be the right decision but I believe RandomDevice can be reeeally slow --- are we sure this is ok? |
(pinging @Keno who had the same concern #32954 (comment)) I think the default should be the safe one. If you know you need tons of random UUIDs, I think you can always swap the RNG argument. But warning this in the docstring would be nice. |
I'm not totally sold on the idea either. There is something nice in knowing that generally all randomness comes from the |
I think the danger of producing the same UUIDs repeatedly when they are supposed to be universally unique is way too high. This is definitely one of those things that has caused problems because people (myself included) just don't realize when they call |
Combined with the fact that UUIDs are sometimes relevant for security, this seems good to me. |
How about using a dedicated default RNG for UUIDs that's initialized from RandomDevice at startup? |
I think that would be fine. It might be good to do something that is more secure as well, e.g. initialize a seed from |
I feel like this is pretty simple and we can just do this and see if anyone actually cares about the performance of generating UUIDs. If they do, then we can consider something more complicated. |
stdlib/UUIDs/src/UUIDs.jl
Outdated
@@ -53,7 +55,7 @@ UUID("cfc395e8-590f-11e8-1f13-43a2532b2fa8") | |||
!!! compat "Julia 1.6" | |||
The default rng has been changed to use Random.RandomDevice as of Julia 1.6 | |||
""" | |||
function uuid1(rng::AbstractRNG=Random.RandomDevice()) | |||
function uuid1(rng::AbstractRNG=uuid_rng) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you make this change? Creating a new RandomDevice()
is extremely cheap on non-Windows, and on Windows having a global uuid_rng
is not thread-safe...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rfourquet I guess misunderstood @JeffBezanson 's comment above?
How about using a dedicated default RNG for UUIDs that's initialized from RandomDevice at startup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My interpretation of it was using an RNG like default_rng()
(currently MersenneTwister()
which is thread-safely initialized), which is therefore immune against the unqualified Random.seed!()
but way faster than RandomDevice()
, but "initialized from RandomDevice()
" means it's seeded from RandomDevice()
at startup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But Stefan's last comment suggests to keep it how it was, because the poor performance of RandomDevice
might considered as a non-problem until someone complains.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay! I reverted 507b454 . I'll leave it alone for now until there's something I should explicitly add/change/remove.
This reverts commit 507b454.
Since it is possible that the default RNG to be changed, I think it'd be better to avoid putting
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me — simple and safe, with the side benefit that it doesn't pull the complexity of all of Random
to the default implementation of uuid4
(which helps greatly in #35894).
Any objections to merging and seeing how it turns out?
Co-authored-by: Rafael Fourquet <fourquet.rafael@gmail.com>
Co-authored-by: Rafael Fourquet <fourquet.rafael@gmail.com>
…g() (JuliaLang#35872) Co-authored-by: Rafael Fourquet <fourquet.rafael@gmail.com>
Description
Fixes #35860
Change
Random.default_rng()
in the UUID functions toRandom.RandomDevice()
Testing
Ran
$ ./julia stdlib/UUIDs/test/runtests.jl
with no issues