Boost logo

Boost :

From: Jos Hickson (jos.hickson_at_[hidden])
Date: 2007-06-12 05:26:36


On 12/06/07, Jos Hickson <jos.hickson_at_[hidden]> wrote:
> On 11/06/07, Andy <atompkins_at_[hidden]> wrote:
> > "Jos Hickson" <jos.hickson_at_[hidden]> wrote in
> > news:fc03d05a0706060823v59628c64xd1bcda61e9fd5f48_at_[hidden]:
> >
> > > On 06/06/07, Peter Dimov <pdimov_at_[hidden]> wrote:
> > >> Jos Hickson wrote:
> > >> > On 05/06/07, Peter Dimov <pdimov_at_[hidden]> wrote:
> > >> >> [snip] ... and if Engine
> > >> >> is a template parameter, we probably need to support engines that
> > >> >> only take a 32 bit seed anyway.
> > >> >
> > >> > Isn't it the case that the maximum seed size is related (equal?) to
> > >> > the difference between the max and min values produced by a
> > >> > particular engine and also that all the engines in Boost Random
> > >> > provide the iterator version of seed?
> > >>
> > >> The seed for mt19937 is 624 words.
> > > Aah, a bit bigger then!
> >
> > I have been thinking about this for awhile now, and maybe I should use
> > Peter's suggestion and only support random number generators that can be
> > seeded with a single number. And xor with rd_.
> >
>
> IMHO such a restriction would be to the detriment of the library
> whereas the solution below would seem a lot better to me.
>

I should point out that "the solution below" refers to your use of
boost::generator_iterator and not to my trite comment about a
Boost.Seed library!

> Really what we need is a Boost.Seed library to compliment Boost.Random
> so that anybody like yourself using the latter doesn't have to spend
> all this time wondering how to seed things generically.
>
> > I have been playing with another solution. I wrapped the seed function
> > in a class that models the random number generator concept. Then used
> > Boost.Iterators' function output iterator, and feed it into the seed
> > function that takes iterators of the random number generator.
> >
> > // not that this is not quite complete
> > class seed_rng
> > {
> > public:
> > seed_rng() : rd_index_(5) {}
> >
> > unsigned operator()() {
> > if (rd_index_ >= 5) {
> > sha1_random_digest_(); // fill rd_ with new data
> > rd_index_ = 0;
> > }
> > return rd_[rd_index_++];
> > }
> > private:
> > sha1_random_digest_();
> >
> > unsigned rd_[5];
> > int rd_index_;
> > };
> >
> > template <typename Engine=boost::mt19937>
> > class uuid_generator {
> > public:
> > uuid_generator() {
> > boost::seed_rgn e;
> > boost::generator_iterator<boost::seed_rng> begin(&e);
> > boost::generator_iterator<boost::seed_rnd> end;
> > en_.seed(begin, end);
> > }
> >
> > boost::uuid operator()() {
> > // get random data from en_
> > // return uuid based on this data
> > }
> > private:
> > Engine en_;
> > };
> >
> > Now this works fine, the slow seed_rng is used to fully seed the random
> > number generator used. It can be specialized for boost::random_device
> > since boost::random_device does not have a seed function.
> >
> > Andy.
> >
>


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