Boost logo

Boost :

From: scleary_at_[hidden]
Date: 1999-11-09 09:47:10


> Regarding what should be the default return value of the PRNG,
> throughout I have assumed that it would be an integer, most likely
> 32-bit. My PERSONAL preference, though, would be for a real,
> either in [0,1] or [0,1). I find these ranges far more useful in far more
> contexts than the straight 32-bit integer. Furthurmore, given the
> unsuitability of the modulus technique to map the PRNG integer output
> onto a certain range, this means that virtually all random number
> requests, except those that request a 32-bit integer directly, will
> first map the PRNG output to this range before remapping it
> to whatever range is required. 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.
>

There is another possibility. What if we design the random number classes
to use fixed precision arithmetic internally? That would avoid the overhead
of floating-point, and also have the default range be [0,1) (assuming all
bits are fractional bits), and also have a direct mapping (no mult/div
necessary) to the range of the underlying unsigned integer type: [0,
numeric_limits<underlying_int_type>::max()].

        -Steve


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