samedi 29 octobre 2016

Haskell Random Number Generator

I want to spawn an enemy at a random time in my game. To do this I wanted to check each frame if a random value [0..100] == 50

spawnEnemy :: World -> World
spawnEnemy (world@World { rndGen = r, enemies = e }) = world { enemies = if rand 0 100 = 50 then Enemy (rand (-200) 200, rand (-200) 200) 0 0 : e else e }
    where
        rand :: Float -> Float -> Float
        rand l h = fst $ randomR (l, h) r

(here rndGen :: stdGen and enemies :: [Enemy])

But rand never seems to return 50. What am I doing wrong here?




Aucun commentaire:

Enregistrer un commentaire