Advertisement
NLinker

Random monad example

Sep 13th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- The code here is stolen from a comment in the MonadRandom source code.
  2. -- dependents on MonadRandom library
  3.  
  4. import Control.Monad.Random
  5.  
  6. die :: RandomGen g => Rand g Int
  7. die = getRandomR (1,6)
  8.  
  9. dice :: RandomGen g => Int -> Rand g [Int]
  10. dice n = sequence (replicate n die)
  11.  
  12. main = do
  13.     rolls <- evalRandIO $ dice 10
  14. print rolls
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement