jeudi 18 février 2016

Random number generating in haskell

When running genRandTupe I continuously get the same random numbers, however when running genrandList with gen as the argument i get a new set of numbers every time. How would I solve this? Why doesn't g = newStdGen generate a new random number?

import System.Random
import System.IO.Unsafe

type RandTupe = (Int,Int)
genRandTupe :: IO RandTupe
genRandTupe = let [a,b] = genrandList g in return (a,b) where g = newStdGen
genrandList gen = let g = unsafePerformIO gen in take 2 (randomRs (1, 20) g)
gen = newStdGen




Aucun commentaire:

Enregistrer un commentaire