Boost logo

Boost :

Subject: Re: [boost] [UUID] version v12
From: Andy Tompkins (atompkins_at_[hidden])
Date: 2008-10-15 11:04:19


Hi Johannes,

I have verified what you wrote. You are quite correct.

On Mon, 13 Oct 2008 13:12:02 +0200, "Johannes Brunen"
<JBrunen_at_[hidden]> said:
> Hello Andy,
>
> after some investigations, I think that I have found the origin of the
> problem:
>
> In seed_rng.hpp the following code is used:
>
> template <typename UniformRandomNumberGenerator>
> inline void seed(UniformRandomNumberGenerator& rng)
> {
> seed_rng seed_gen;
> boost::generator_iterator<seed_rng> begin(&seed_gen);
> boost::generator_iterator<seed_rng> end;
> rng.seed(begin, end);
> }

I could pass the seed_gen to the end iterator, but then as soon as begin
produces the same random number as end, the seed function will stop.
May not happen in practice, but could happen. I like your solution (set
generator_iterator::m_gen to NULL in the default constructor) much
better.

>
> Problematic is the construction of the end iterator. Looking into the
> code
> (boost/generator_iterator.hpp) shows, that the default constructor of
> generator_iterator does not initialize its member variables.
>
> generator_iterator() {}
>
> Howerver, the mersenne_twister seed code does compare the two given
> iterators as shown below (boost/random/).
>
> template<class It>
> void seed(It& first, It last)
> {
> int j;
> for(j = 0; j < n && first != last; ++j, ++first)
> x[j] = *first;
> i = n;
> if(first == last && j < n)
> throw std::invalid_argument("mersenne_twister::seed");
> }
>
> As the end iterator is not initialized the way is open for all throwing
> the
> invalid_argument exception.
>
> Locally, I did solve the problem by patching the default constructor of
> class generator_iterator.
>
> If this is a valid solution of the problem, it would be fine if anyone
> applies the correction to the boost code.
>
> Greetings,
> Johannes
>

Thanks,
  Andy.


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