Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 1999-11-09 06:56:48

Jeet -

>However, concerns about the cost of the division
involved, when such division may be uneccessary (imagine users who do
need the 32-bit integers -- if we go the [0,1] route, they will be
getting numbers that have been divided by 0xfffffff and then multiplied
by 0xfffffff: perverse!) led me to stick to the "PRNG gives 32-bit
integer" assumption.<

Looking at random_shuffle, the argument to operator() must be
iterator_traits<iterator_type>::distance_type - and that need not be int or
even int32_t - so how about:

template <class Arithmetic>
class generator
   Arithmetic operator(); // uniform distribution
   Arithmetic operator(Arithmetic max_value); // uniform in restricted
range 0 - max_value

template <class Arithmetic, class Gen = default_generator_type<Arithmetic>
class ramdom_number_type
   Arithmetic operator(); // maps uniform distribution to required
   Arithmetic operator(Arithmetic max_value); // as above

Probably you would need different template behaviour for integral and
floating point types (to avoid generating NAN's) - but a traits class
should be able to deal with that (or use

Sorry to go off at another tangent...

- John.

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