samedi 23 avril 2016

Random Number Set Haskell

i need to take one random element from a set of int. I am trying to use the function elemAt :: Int->Set a->a but i need to randomly generate the Int which will be used in the first argument of elemAt, but i am having a problem because randomRIO is a monadic function. How can i use randomRIO in a funcion that returns an int?E.g:

function :: Int->Int
function i = x <- randomRIO(0,i-1)

What i am trying to do is something like this:

element set = elemAt (function (size set)) set




Aucun commentaire:

Enregistrer un commentaire