
Duncan Coutts wrote:
So you end up with pure functions like:
shuffle :: RandomGen g => g -> [x] -> [x]
Thanks for the help, Duncan. I'm confused on one point. Don't you always need the new state of the generator back? So wouldn't this need to be: shuffle :: RandomGen g => g -> [x] -> (g,[x])
Another approach is to hide the 'g' inside a monad. That's what MonadRandom is all about. eg:
shuffle :: [x] -> Rand [x]
One tutorial mentions the class Gen in the Test.QuickCheck module. Is "Rand" a different class defined somewhere else?
The tutorials above explain about the other random functions, for getting values of different types (not just Int) and restricted ranges of number etc.
Of course at some point you want to seed the random number generator with some initial genuinely random value (not like the 12345 we used above). That is the only place in your random-handling code that needs to do IO. All the rest of it can be pure.
What function gives you that initial random seed? (Grabs it from the system clock?) Thanks, Mike