The story begins here:

Steve Horne:

   /BTW - why use an IO action for random number generation? There's a
   perfectly good pure generator. It's probably handy to treat it
   monadically to sequence the generator state/seed/whatever but random
   number generation can be completely pure. /

===================

Bardur Arantsson:

   /*Pseudo* random number generation can of course be pure (though
   threading the state would be tedious and error-prone). If you want
   truly random numbers you cannot avoid IO (the monad). /

??? ??????? :
If seed depends of psudo random event, for example of current systime,
we must use IO action.
Bardur, Lev, of course you try to be helpful, but you are answering wrong questions.

"Truly random" numbers are very rarely used, forget about them. "Standard" r. generators (pseudo-random) in Haskell are monadic, because the relevant algorithms are stateful. Congruential, Fibonacci, Mersenne Twister, whatever, is a function, more or less:
(newValue,newSeed) = rgen seed

The monadic approach serves mainly to hide the seed.
Some people prefer to use random streams, no monads, so the question of Steve Horne is not universal. But anyway, even without bind, the user will have to chain the seeds in some way.

Still, I dont understand what does S.H. mean by a "perfectly good pure generator".
Tell more please (unless you just mean a stream, say:

str = map fst (iterate (\(v,sd) -> rgen sd) (v0,sd0))
)

Jerzy


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to