On 02-Feb-2000, Simon Peyton-Jones <[EMAIL PROTECTED]> wrote:
> The library is currently based on the RandomGen class,
> whose signature is:
> 
>       class RandomGen g wher
>         next :: g  -> (Int, g)
>         split :: g -> (g, g)
> 
> The difficulty is that there is absolutely no robust way to
> use such a generator to generate random numbers uniformly
> distributed in a given range.  Why not?  Because there's no
> clue as to the precise range of Ints produced by next.

Hmm...  the current specification says that next returns
`(one Int's worth)' of (pseudo-random) bits.
So isn't the range supposed to be the whole range of `Int'?

If not, what's the rationale?
Wouldn't it be easiest if the RNG just guaranteed to
return integers that range over the whole range of `Int'?
Note that the range of `Int' can be obtained using the `minBound'
and `maxBound' functions in the standard prelude.

|    * The next operation allows one to extract at least 30 bits (one
|      Int's worth) from the generator, returning a new generator as
|      well. The integer returned may be positive or negative.

That wording is a little unclear, so I suggest clarifying
it as follows:

     * The next operation allows one to extract a pseudo-random Int
       from the generator, returning a new generator as well.
       The integer returned may be positive or negative.
       Over a sufficiently large sequence of calls to next,
       the integers returned should be uniformly distributed
       over the whole range of Int (from minBound to maxBound,
       inclusive).

If that clarification were made, there would be no need to
introduce the `genRange' method that Simon P-J suggested.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.

Reply via email to