
On 05/06/07, Peter Dimov <pdimov@mmltd.net> 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 unlikely).
class uuid_generator { unsigned rd_[5]; mt19937 en_;
uuid_generator() { init rd_; seed en_ with rd_[4]; }
operator() { 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? Jos