Skip to content

Instantly share code, notes, and snippets.

@MiyamonY
Created February 27, 2015 11:19
Show Gist options
  • Save MiyamonY/3699bdd795c3ab9696b6 to your computer and use it in GitHub Desktop.
Save MiyamonY/3699bdd795c3ab9696b6 to your computer and use it in GitHub Desktop.
import System.Random
threeCoins :: StdGen -> (Bool, Bool, Bool)
threeCoins gen =
let (firstCoin, newGen) = random gen
(secondCoin, newGen') = random newGen
(thirdCoin, _) = random newGen'
in (firstCoin, secondCoin, thirdCoin)
-- threeCoins (mkStdGen 100)
-- (True,False,False)
randoms' :: (RandomGen g, Random a) = g -> [a]
randoms' gen = let (value, newGen) = random gen in vlue : randoms' newGen
finiteRandoms :: (RandomGen g, Random a, Num n) => n -> g -> ([a], g)
finiteRandoms 0 gen = []
finiteRandoms n gen =
let (value, newGen) = random gen
(restOfList, finalGen) = fomoteRamdoms (pred n) newGen
in (valu: restOfList, finalGen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment