Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2002-01-30 09:27:54


Dear Jens, dear Booster

We now daily use the boost::random library in our production codes, and
have collected our experiences with it. As I have heard that the library
has been proposed as a possible addition to the C++ standard, I wish to
bring up our experiences, and propose a minor change that would greatly
help generic programming with boost::random.

The problem we face at the moment is that the arguments to the seed(...)
function and to the non-default constructor are dependent on the
generator.
This makes it impossible to just change generators, without changing
the code, when the code needs to seed a generator, which happens
in many applications, e.g. when a new generator needs to be
spawned dynamically in an application.

One solution would be to always require a seed(uint32_t ). However the
problem there is that for generators like the LCG many integers are bad
seed values, and the good/bad values differ from generator to generator.
Also, a lagged Fibonacci generator, or a Mersenne Twister (MT) needs a
long
seed block instead of a single integer.

There are however solutions to this problem, as implemented e.g. in the
SPRNG library (http://sprng.cs.fsu.edu/). These solutions take a
"sequence number", a nonnegative integer, and convert it into a good
seed for lagged Fibonacci generator. Similar algorithms can be
implemented
for the MT, or also for LCGs. This makes it possible to write more
generic
codes.

Since I do not want to change the semantics of seed(uint32_t) where
it is avaiable, I propose to add the following members to the generators:

   sequence(uint32_t n) ; // seeds the generator with the n-th good seed
   static const uint32_t max_sequence; // n can take all values
0..max_sequence
                                       // whereever possible this should
be the
                                       // largest possible integer

Alternatively we could replace uint32_t by an integral sequence_type,
to make it more flexible.

Also, these member should be propagated through the adaptors, so that
they
can also be seeded in this way.

If this proposal meets with approval, we will start implementing it and
can
then present it to Boost for further discussions.

Best regards,

Matthias


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