-- $Id: random.ghc,v 1.5 2001/05/18 07:10:55 doug Exp $ -- http://www.bagley.org/~doug/shootout/ module Main(main) where import System(getArgs) import Numeric(showFFloat) main = do ~[n] <- getArgs putStrLn (showFFloat (Just 9) (randloop (read n::Int) 42 0.0 100.0) "") return 1 randloop :: Int -> Int -> Double -> Double -> Double randloop 0 seed r max = r randloop n seed r max = randloop (n-1) newseed newrand max where normalize x max = (fromIntegral x) * (max / imd) newseed = (seed * ia + ic) `mod` im newrand = normalize newseed max im = 139968 imd = fromIntegral im ia = 3877 ic = 29573