[Haskell-cafe] random question
lrpalmer at gmail.com
Wed Oct 7 17:10:46 EDT 2009
On Wed, Oct 7, 2009 at 2:59 PM, Michael Mossey <mpm at alumni.caltech.edu> wrote:
> My thread about randomness got hijacked so I need to restate my remaining
> question here. Is it acceptable to write pure routines that use but do not
> return generators, and then call several of them from an IO monad with a
> generator obtained by several calls to newStdGen?
It's gross. What if you don't want IO as part of this computation?
If you have a random generator that supports splitting (something
rather hard to do from what I understand), I prefer not to return the
new generator but instead to split it. So, using your shuffle:
> shuffle :: RandomGen g => g -> [a] -> [a]
> shuffle = ...
foo :: RandomGen g => [a] -> [a] -> g -> ([a],[a])
foo xs ys gen =
let (gen1, gen2) = split gen in
(shuffle gen1 xs, shuffle gen2 ys)
More information about the Haskell-Cafe