jeudi 14 mai 2020

How to use a do block in a function in Haskell?

I want to generate 2 random Int inside a function and use them when calling some other functions. Those other functions expect an Int, so I am trying to get the random values inside a do block. Can someone tell me how I should do this properly?

simmulatedGen :: [[Bool]] -> [[Bool]] ->Int -> Double -> Int -> [[Bool]]
simmulatedGen seed minim _ _ 0 = minim
simmulatedGen seed minim dimensiuni t iteratii = do
        {i <- getStdRandom $ randomRIO (0,dimensiuni - 1 :: Int)
        ;j <- getStdRandom $ randomRIO (0,31:: Int)}
    let vecin = selectVecin i j seed
        valoareVecin = deJong dimensiuni (bitGenToDoubleArray dimensiuni vecin)
        valoareMinim = deJong dimensiuni (bitGenToDoubleArray dimensiuni minim)
        percentage = getStdRandom $ randomIO :: Double in  
    if valoareVecin < valoareMinim then simmulatedGen seed vecin dimensiuni t (iteratii - 1) else if t > percentage then simmulatedGen seed vecin dimensiuni t (iteratii - 1) else
                                                            simmulatedGen seed minim dimensiuni t (iteratii - 1)



Aucun commentaire:

Enregistrer un commentaire