mardi 23 août 2016

Haskell: How to use random integer from randomRIO in a function that returns a boolean

I am new to Haskell and i'm having a problem with using the IO Int from randomRIO function. My goal is to get a random Int value, say r, and to return True if r < x or false otherwise, but i don't know how to do it.

my function should look like:

randomCompare :: Int->Bool

randomCompare x

  | x < r = True -- somehow i want to r <- randomRIO(start,end) 

  | otherwise = False                

I know there is a designed intention with keeping IO vals in context for purity etc.. but i don't see why using a random number for a Boolean function should be "bad".

Thanks.




Aucun commentaire:

Enregistrer un commentaire