関数型プログラミング言語Haskell Part5
■ このスレッドは過去ログ倉庫に格納されています
0202デフォルトの名無しさん
2006/06/12(月) 13:18:54module MyRandom where
import System.Random
import System.Time
import System.IO.Unsafe
getPicosec :: IO Integer
getPicosec = getClockTime >>= return . ctPicosec . toUTCTime
newStdGenFromClock :: IO StdGen
newStdGenFromClock = getPicosec >>= return . mkStdGen . fromInteger
randomsRIO :: Random a => (a, a) -> IO [a]
randomsRIO = (newStdGenFromClock >>=) . (return .) . randomRs
-- randomsRIO r = newStdGenFromClock >>= return . randomRs r
randomsIO :: Random a => IO [a]
randomsIO = newStdGenFromClock >>= return . randoms
randomsRUnsafe :: Random a => (a, a) -> [a]
randomsRUnsafe = unsafePerformIO . randomsRIO
randomsUnsafe :: Random a => [a]
randomsUnsafe = unsafePerformIO randomsIO
これをインポートして take 10 $ randomsRUnsafe (0, 5) とかすれば乱数リストが取れた。
■ このスレッドは過去ログ倉庫に格納されています