Created
February 11, 2019 23:08
-
-
Save Lysxia/ddf1ea3bb3b81cb7b6965a387c044984 to your computer and use it in GitHub Desktop.
infinite random list, with MonadRandom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Monad.Random | |
| randomList :: MonadRandom m => m [Double] | |
| randomList = do | |
| start <- getRandomR (0.7 :: Double, 1.2) | |
| go start | |
| where go prev = do | |
| new <- getRandomR (min 0.7 (prev-0.1), max (prev+0.1) 1.2) | |
| acc <- go new | |
| return (new : acc) | |
| foo :: IO () | |
| foo = evalRandIO randomList >>= (print . take 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment