>>> Does anybody know of work using monads to encapsulate a source of
>>> random numbers?

>> Is the global random number generator, in section
>> 17.3 of the Haskell 98 library report, the sort of thing you're after?

> No; that appears to embed a generator in the IO monad. Not what I'd
> hoped for.

I'm not sure if this is what you are looking for but since I consider the
IO monad overkill I use a state monad:

  newtype Rand a = Rand (StdGen -> (a,StdGen))

Of course you don't have to use StdGen, and the monad takes care of
threading the generator through your code.  Generating random numbers is
accomplished by

  rand :: (Random r) => Rand r
  rand = Rand random

Dana


Reply via email to