[Haskell-cafe] Random Numbers for the beginner ?
yu- at div.club.ne.jp
Tue Jul 6 17:48:12 EDT 2004
On Tue, 06 Jul 2004 19:09:53 +0000
"Crypt Master" <cryptmaster at hotmail.com> wrote:
> So I added RollDice to my module. This doesnt error, but it doesnt return
> anything except blank spaces:
> HasGal> rollDice
> Integers or nums should automatically have show correct? So this should show
> me something ?
rollDice is an action of type IO Int, not a number of type Int.
Main> do n <- rollDice; print n
> Ultimatly I want to get randomRs infinite list working so I can build
> randNums = (take (length popList) [1..])
> where the length of pop list is how many random numbers I want. My code
> works as it, just need to replace [1..] with some random numbers.
rollDices :: RandomGen g => g -> [Int]
rollDices = randomRs (1, 6)
randNumInfSeq :: [Int]
randNumInfSeq = rollDices (mkStdGen 0)
Main> do g <- getStdGen; let randNums = take 20 $ rollDices g in print randNums
Main> print $ take 20 $ randNumInfSeq
Hope it helps,
More information about the Haskell-Cafe