Boost logo

Boost :

From: Csaba Szepesvari (cszepes_at_[hidden])
Date: 2003-05-20 02:47:03


Dear Matthias,

Thanks for the answer.

> Some generators use not only a single seed number but a seed block of
> many numbers. Instead of returning a single seed number (which is the
> not possible), there are operators << and >> to save the state into a
> std::ostream and to restore it from a std::istream

I have actually put a simpler interface on top of boost::random serving my
simple needs. Usage looks something like:

rb::UFRand ufrand; // this saves two lines, see below
rb::UFRand::Seed seed = ufrand.set_seed();// "random initialization", saves
"state" (presently a number)
float x = ufrand();

The default implementation uses linear congruantial generators from boost.
(Reason? I do not like to type a lot and remember long names. Also, if I
decide later that I need a different implementation I could do that.)
I would think this will be quite a common usage for the average user (if she
cares about random number generation at all).
My motivation is to control random number generation in my programs that has
simple needs (e.g. I typically do not need multidimensional "independent"
samples etc.)
((What about adding such a simple interface on the top of user to courage
usage of the library? My default implementation uses a singleton with
initializers to store the base random generator..I am happy to contribute
these if there is any interest.))

As far as I see operator<<,>> could be used to return the seed (for LCGs),
however, it would be far from being "elegant".

>
> > The issue comes in when using seed without params (for "random"
> > initialization).
>
> AFAIK using seed() without a parameter will not give a "random"
> initialization but the same initialization at every call.

Sorry, I was not clear - I meant the set_seed in my interface on the top of
boost the user has this choice.

Bests,

  Csaba
---------------------------------

Comparision with boost interface:
----------------------------------------------------------------------
::boost::minstd_rand base_rand;
::boost::uniform_01< ::boost::minstd_rand,float> ufrand(base_rand);
----------------------------------------------------------------------
Compare this with a single line of code..: "UFRand ufrand"
I am lazy, but I know quite a few other people who would say that no, never
such a complicated thing!
I work with them day by day and need to let them using boost::random for
good reasons hence I made my simple interface on the top of boost.

Actually, there is another problem with the above 2 lines:
In a project with multiple files not alone multiple libraries, the user
needs to take care about making base_rand global.
This means additional work.


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