Fergus Henderson wrote:
>
> 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.
I would accept this change. I do think it limits the number of useful
RNG's under Haskell. Many RNG's don't "naturally" generate a 32-bit
number, and it makes it more difficult to write a portable RNG in
Haskell, since the range of Int can vary across implementations.
Maybe under Haskell 2, we could say that next just generates any
instance of Integral and Bounded, and that way we can use
maxbound/minbound to determine the range, and then the RandomGen
implementer could optionally create his own instance type of
Integral/Bounded to use. eh?
Matt Harden