Skip to content

Instantly share code, notes, and snippets.

@tan-yuki
Created May 21, 2017 21:50
Show Gist options
  • Save tan-yuki/6837e9d595b66fe166e08affac09a994 to your computer and use it in GitHub Desktop.
Save tan-yuki/6837e9d595b66fe166e08affac09a994 to your computer and use it in GitHub Desktop.
import System.Random
dice :: StdGen -> Int
dice gen = num
where (num, _) = diceWithRandomGen gen
diceWithRandomGen :: StdGen -> (Int, StdGen)
diceWithRandomGen = randomR (1, 6)
threeTimesDiceRoll :: StdGen -> (Int, Int, Int)
threeTimesDiceRoll gen = (first, second, third)
where (first, firstGen) = diceWithRandomGen gen
(second, secondGen) = diceWithRandomGen firstGen
(third, _) = diceWithRandomGen secondGen
main :: IO ()
main = do
gen <- getStdGen
print $ dice gen
print $ threeTimesDiceRoll gen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment