Boost logo

Boost :

From: Andy (atompkins_at_[hidden])
Date: 2007-05-07 14:30:10


"Peter Dimov" <pdimov_at_[hidden]> wrote in
news:002e01c790c0$0f2d3510$6407a80a_at_pdimov2:

> 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?

Good idea. Something like:

template<typename Engine>
boost::guid guid::create(Engine& e = boost::mt19937(get_seed()));

where get_seed() does something like what you said below.

I want to be able to call the create function with a default Engine
because I don't want to force users to create one themselves. The only
downside is for people who do want a different engine/seed, they will
have to pass that engine to the function everytime they call it.

>
> 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
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

Andy.


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