Hello,
Undoubtedly you can write your own monad and encapsulate
the random number generation yourself. It is just an
instance of a state monad.
Nevertheless, the problem of using state monads for random number
generation is that the code must be single-threaded, which is
sometimes too restrictive -- afterall all you want is just
some 'random' number. Quite a while ago I read a paper about
using some techniques to encapsulate impure random number
generation in a syntatic construct which looks pure. You
need to pass around the seed explicitly but you get more
freedom. It's not exactly what you want but you may find
it interesting.
F. Warren Burton and Rex L. Page. Distributed random number
generation. Journal of Functional Programming, 2(2):203-212,
April 1992.
sincerely,
Shin-Cheng Mu
Norman Ramsey wrote:
>
> > > 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.
>
> N"