Read the boost manual right-side up

(cherry picked from commit 3f0f846435)
This commit is contained in:
Marek Roszko 2022-03-24 18:13:39 -04:00 committed by Mark Roszko
parent bf8c7d7697
commit 0ea7dabc12
1 changed files with 2 additions and 14 deletions

View File

@ -41,22 +41,10 @@
// boost:mt19937 is not thread-safe // boost:mt19937 is not thread-safe
static std::mutex rng_mutex; static std::mutex rng_mutex;
// We use a little helper class to ensure our static rng object is seeded
// with a random seed on startup before it's passed to the uuid generator object
class GENERATOR_INIT_HELPER
{
public:
GENERATOR_INIT_HELPER( boost::mt19937& aRng )
{
boost::uuids::detail::random_provider seeder;
aRng.seed( seeder );
}
};
// Static rng and generators are used because the overhead of constant seeding is expensive // Static rng and generators are used because the overhead of constant seeding is expensive
// We break out the rng separately from the generator because we want to control seeding in cases like unit tests // We break out the rng separately from the generator because we want to control seeding in cases like unit tests
static boost::mt19937 rng; static boost::uuids::detail::random_provider seeder; // required to ensure the rng has a random initial seed
static GENERATOR_INIT_HELPER initHelper( rng ); static boost::mt19937 rng( seeder );
static boost::uuids::basic_random_generator<boost::mt19937> randomGenerator( rng ); static boost::uuids::basic_random_generator<boost::mt19937> randomGenerator( rng );
// These don't have the same performance penalty, but we might as well be consistent // These don't have the same performance penalty, but we might as well be consistent