From: Andy (atompkins_at_[hidden])
Date: 2007-06-05 15:49:53
"Jos Hickson" <jos.hickson_at_[hidden]> wrote in
> On 05/06/07, Peter Dimov <pdimov_at_[hidden]> wrote:
>> Jos Hickson wrote:
>> > Understood. However, if the best implementation of uuid::create()
>> > depends on which of two usage patterns is assumed ("batch" or "one
>> > per program") maybe a better approach is to have both
>> > uuid_generator (for batch purposes) and uuid::create() (for the
>> > one-per-program usage) with the generator seeded using the
>> > randomness that uuid::create() uses.
>> We can consider dropping the two forms of uuid::create entirely and
>> only provide uuid_generator. The discussion has demonstrated that
>> they have some non-obvious pitfalls (one is slower than expected, the
>> other assumes that the user has supplied a good seed and this is
>> class uuid_generator
>> unsigned rd_;
>> mt19937 en_;
>> init rd_;
>> seed en_ with rd_;
>> generate a 128-bit number using en_;
>> xor it with rd_[0..3];
>> return a uuid based on it;
>> seems to address both issues.
> Yes, that's probably a better idea but if both versions of create()
> are dropped then should there be some means of providing a different
> engine for those who really want to?
Yes. Change uuid_generator to be a template
template <typename Engine>
seed en_ with rd_;
generate a 128-bit number using en_;
xor it with rd_[0..3];
return a uuid based on it;
But, how does the xor part help? It is just for the case where we are
only producing one uuid?
Also it is possible that one chooses to use a random number generator
that can't be seeded (for example based on /dev/urandom), and I'm not
sure how this fits in. Actually, this could just be a specialization.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk