module Main where

-- Compile eg with
-- ghc -O3 -optc-O3 -optc-ffast-math -fexcess-precision -funfolding-use-threshold=16 --make testMT
-- 
-- -ddump-simpl makes the Core.

import Mersenne

genRNums32 :: MT32 -> Int -> IO MT32
genRNums32 (MT32 mt pos) nCnt = gRN nCnt pos
	where 
	      gRN :: Int -> Int -> IO MT32
	      gRN 1 iCurr = do 
			(r,iNew) <- next32 mt iCurr
			putStrLn $ (show r)
			return (MT32 mt iNew)
	      gRN nCnt iCurr = do
			(_,iNew) <- next32 mt iCurr
			gRN (nCnt-1) $! iNew

genRNums64 :: MT64 -> Int -> IO MT64
genRNums64 (MT64 mt pos) nCnt = gRN nCnt pos
	where 
	      gRN :: Int -> Int -> IO MT64
	      gRN 1 iCurr = do 
			(r,iNew) <- next64 mt iCurr
			putStrLn $ (show r)
			return (MT64 mt iNew)
	      gRN nCnt iCurr = do
			(_,iNew) <- next64 mt iCurr
			gRN (nCnt-1) $! iNew

main = do
	putStrLn "Testing Mersenne Twister."
	-- mt32 <- initialiseGenerator32 100
	-- genRNums32 mt32 10000000
	mt64 <- initialiseGenerator64 100
	genRNums64 mt64 10000000
