Skip to content

Instantly share code, notes, and snippets.

@righ1113
Last active January 24, 2021 01:13
Show Gist options
  • Save righ1113/84d4e4c93b5df49053de2e92dd3f0c43 to your computer and use it in GitHub Desktop.
Save righ1113/84d4e4c93b5df49053de2e92dd3f0c43 to your computer and use it in GitHub Desktop.
Haskell の乱数でごにょごにょ
module Rand2 where
-- stack install random
-- stack install list-t
-- stack exec ghci
import Control.Monad.IO.Class ( liftIO )
import ListT ( ListT, toList, cons, take )
import System.Random ( Random(randomIO) )
t3 :: ListT IO Int
t3 = do
x <- liftIO (randomIO :: IO Int)
cons x t3
-- IO [Int] の乱数が得られるところがポイント
output :: IO ()
output = do
li <- toList $ ListT.take 10 t3
print li
{-
*Rand2> output
[7616927328998369033,6970782903781268443,-1509938769401207081,-2789264750098693865,-6524417077297424569,8403979199680420436,-3097298192134792937,-2736699795503652525,-4754186463647322678,5658901448509988002]
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment