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
Utilize std::shuffle #9004
Utilize std::shuffle #9004
Conversation
std::random_shuffle is deprecated and removed starting from C++17, so we might better use std::shuffle which uses URBG: https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator under the hood for a better randoms generation.
constant seed is not acceptable. Better not seeding at all. |
pdns/misc.cc
Outdated
@@ -597,7 +599,7 @@ void shuffle(vector<DNSZoneRecord>& rrs) | |||
break; | |||
|
|||
if(second-first > 1) | |||
random_shuffle(first,second); | |||
shuffle(first, second, std::default_random_engine(seed)); |
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.
It appears default_random_engine
is implementation defined, probably including the constructor signature. Should we really use this?
I'm also concerned about providing a static seed of zero to an implementation defined random engine.
https://www.cplusplus.com/reference/random/default_random_engine/ suggests that it could be a linear_congruential_engine
which has a default seed value (of 1u)...
I much prefer to see a wrapper adding a |
Something like this:
Though using it in |
This is how it could be done. I moved the shuffle functions to dns_random.cc since that avoid linking (indirectly) all auth tools with openssl. Also, I'd really like a |
It seems wrong to pull in dnsparser.hh and the likes in the dns_random code indeed (which has not a lot to do with DNS, but meh).
We used to have that and it led to parts of the code silently storing the result in a |
I understand the concerns. It just feels wasteful to always compute de-biased value when we know the full 32-bits could be used used. |
We might use smth like:
which makes more sense than static seed of zero but it doesn't solve your wish to centralize this approach. I found out we have another brick in the wall in syncres.cc which utilizes random_shuffle as well. |
An issue with random devices is that they might not be available in chroots. |
Checking what's going on with the unit test failures. |
The problem in the recurssor is coming from the a
|
What seems to be happening is a self-move that boost does not like. I'll comment out the offending syncres.cc change for now But we need to find out what's happening here. maybe this revealed some issue in |
Disable until we know what is going on.
Rec bulk test still fails., with same assertion, but now coming from |
not using |
Note that this assertion is gone in boost's trunk: boostorg/container@5f0ce60 |
It doesn't look like an issue in |
Agreed. I'm trying to push a workaround that avoids the self-assignment in |
Continued in own branch in #9016 |
std::random_shuffle is deprecated and removed starting from C++17, so we
might better use std::shuffle which uses URBG:
https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator
under the hood for a better randoms generation.
Short description
utilize std::shuffle
Checklist
I have: