[Haskell] help -- need a random number

Johannes Waldmann waldmann at imn.htwk-leipzig.de
Thu Apr 26 13:06:49 EDT 2007


> I need some random numbers. 

in the IO Monad, hiding the use of a generator

do x <- randomRIO (0, 1 :: Double) ; print x

you can also make the state explicit:

do g0 <- getStdGen ; let { ( x, g1 ) = randomR ( 0, 1::Double) g0 } ;
    print x

a RandomGen is actually the state object for the generator,
much like  http://java.sun.com/javase/6/docs/api/java/util/Random.html

best regards, J.W.




More information about the Haskell mailing list