Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Created February 11, 2019 23:08
Show Gist options
  • Select an option

  • Save Lysxia/ddf1ea3bb3b81cb7b6965a387c044984 to your computer and use it in GitHub Desktop.

Select an option

Save Lysxia/ddf1ea3bb3b81cb7b6965a387c044984 to your computer and use it in GitHub Desktop.
infinite random list, with MonadRandom
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