Skip to content

Instantly share code, notes, and snippets.

@ijt
Created October 3, 2011 00:13
Show Gist options
  • Save ijt/1258156 to your computer and use it in GitHub Desktop.
Save ijt/1258156 to your computer and use it in GitHub Desktop.
Example of how to use the Random monad in Haskell
-- cabal install MonadRandom
-- ghc random_monad_example
-- ./random_monad_example
-- The code here is stolen from a comment in the MonadRandom source code.
import Control.Monad.Random
die :: RandomGen g => Rand g Int
die = getRandomR (1,6)
dice :: RandomGen g => Int -> Rand g [Int]
dice n = sequence (replicate n die)
main = do
rolls <- evalRandIO $ dice 10
print rolls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment