samedi 11 novembre 2017

Random values in range haskell

I am trying to get 2random values each time my function is called. After that I am trying to check if the value is equal to 2. This never happens while I call the first function 60 times/second. I have the following code:

updateGame dt gs@(_ _ _ gen)  = gs {ranGen = gen'', test = testRandom' dt r1 r2}
                                          where
                                            (r1, gen')  = randomR (0, 10) gen  :: (Float, StdGen)
                                            (r2, gen'') = randomR (0, 10) gen' :: (Float, StdGen)

In this example gen/ranGen is a StdGen from System.Random. In testrandom I check both r1 and r2 if they are 2. When I change the range to (0,0) and check for 0, it does work, which confuses me.




Aucun commentaire:

Enregistrer un commentaire