Boost logo

Boost Users :

Subject: Re: [Boost-users] [random] number of seed values required to seed engine
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-03-27 11:00:01


On 03/26/2012 10:55 PM, Thomas Mang wrote:
> Hi,
> Consider the mersenne_twister_engine<...> member function seeding a
> engine with an iterator range of seed values:
> template<typename It> void mersenne_twister_engine<...>::seed(It &, It);
> Is there some nice way to figure out how many seed values this function
> will need?

Create a ridiculously large vector and
see how far the iterator is advanced.

> I have used mt19937 and had to inspect the code to figure out it needs
> 624. I would find it very useful if this information is somewhere
> readily provided through some organized interface, e.g. a member
> function or a static class member stating that value. Same for other
> engine types.

It would be easier to use seed_seq, which is
part of the C++11 library. The iterator
interface was dropped for C++11.

> BTW, I find it surprising that the first parameter is a reference to an
> iterator, and hence the input argument itself will be altered. Is that
> by design? If so what's the rationale? I think it's fairly odd
> behaviour, giving rise to unnecessary dangerousness and should become
> documented more clearly (big warning in bold flashing red letters etc.
> :) ).

This is intentional. The reason is so that
the caller knows how many values were consumed.
This is used by adaptors that take multiple
engines, for example.

In Christ,
Steven Watanabe

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at