|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-05-07 11:53:07
Andy wrote:
> I agree that the create function needs improvement. It suffers from
> threading problems (because of static variables) and from a hard coded
> random number generator (also a hard coded seed).
>
> My solution is to create a generator class, as follows:
>
> // maybe a better name
> // maybe a different default random number generator
> template <typename UniformRandomNumberGenerator = boost::mt19937>
> class random_guid_generator : boost::noncopyable
[...]
> random_guid_generator<> guid_gen;
> guid g = guid_gen.create();
Why not just add an Engine & e parameter to guid::create?
For the default seed, you might want to look into combining several sources
of entropy (unpredictable values) such as
- time(0)
- clock()
- the values of an unsigned char[] array that is allocated on the stack and
not initialized
- the addresses of some variables or functions
- the address of a newly allocated object
- anything else that you can come up with
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk