Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 2000-02-17 14:47:47

At 11:14 PM 2/16/00 +0100, Jens Maurer wrote:

>Back in November last year, Jeet Sukumaran posted a proposal for a
>random number library framework. The original proposal was based
>on a polymorphic class hierarchy, but most of the people who
>felt that some template-based solution might be better.
>Unfortunately, I haven't received anything about that subject since.
>Thus, I have created a new directory "random" in the doc vault and
>put up my proposal for a framework:
>Similarities to Jeet Sukumaran's proposal are not entirely
>however, mine is completely template-based (not a single virtual
>I have currently implemented the following generators:
>linear congruential (lrand48()-clone, minimal standard (both
>mersenne twister (mt11213b, mt19937) (anew from the paper, not LGPL-
>The following distributions are available:
>uniform on real [0..1) and [min,max]
>geometric, exponential, gaussian, uniform on an n-dimensional sphere
>I am aware that the implementation still has its rough edges, but
>feel free to comment on that as well.


* Is there a reason you didn't specify the interface to meet the
RandomNumberGenerator requirements in 25.2.11
[lib.alg.random.shuffle] by providing operator()(long) in addition to
the Generator (operator()()) requirements?

* It often seems useful to be able to get the current rng value (via
value() and/or a conversion operator) without stepping to the next
value. It saves setting up a work variable just to hang on to the
value through a few lines of code.

* Supplying operator++() seems to me to make the intent of user code

      some_rng_class rng;
      while ( ... )
         f1(++rng); // call a function with a new rng value
         f2(rng); // call a function with the current rng value
         f2(rng.value()); // some prefer to avoid a conversion

* The hyphens in file names make me slightly nervous. For example,
even though Win NT permits the hyphens, VC++ chokes on them in
project names. I think that underscores may be slightly more
portable. Not a big deal one way or the other.

* Another nit: holding source line lengths to a maximum of 80
columns makes it easier to read and print code.

* I tried to compile random-test.cpp. Microsoft VC++ 6.0 sp3
doesn't allow in class initializers, so gets errors on the following.
 Maybe some VC++ experts can suggest an easy way around:

  static const bool has_fixed_range = true; static const result_type
min_value = 0;
  static const result_type max_value = static_cast<result_type>(-1);

* Metrowerks CodeWarrior said this conversion was illegal:

  static const result_type max_value = static_cast<result_type>(-1);

* Other CodeWarrior errors:

  Error : ambiguous access to overloaded function
  'boost::rand48::rand48(unsigned long long)'
   random-test.cpp line 76 rand48 rnd(5);

  Error : ambiguous access to overloaded function
  'boost::rand48::seed(unsigned long long)'
  random-test.cpp line 78 rnd.seed(17);

This points up a problem: some platforms don't yet support long
long; it isn't part of the C++ Standard so #ifdefs are needed, I am
afraid. Metrowerks tries to support it, IFRCC, but overloading
doesn't seem to be working.

* There is an undefined symbol in random.hpp: M_PI

Rough edges aside, this looks like a nice package! Thanks for
working on it.


Boost list run by bdawes at, gregod at, cpdaniel at, john at