Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-06-05 10:01:49


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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk