From: sewardj Date: Mon, 22 Nov 1999 12:12:09 +0000 (+0000) Subject: [project @ 1999-11-22 12:12:09 by sewardj] X-Git-Tag: Approximately_9120_patches~5528 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=2935b8d2b355b3ec45f247d05b6205a195612662;p=ghc-hetmet.git [project @ 1999-11-22 12:12:09 by sewardj] Implement Random.setStdGen and Random.getStdGen for Hugs. --- diff --git a/ghc/lib/std/Random.lhs b/ghc/lib/std/Random.lhs index 25b4752..9bf845e 100644 --- a/ghc/lib/std/Random.lhs +++ b/ghc/lib/std/Random.lhs @@ -39,7 +39,6 @@ import PrelNumExtra ( float2Double, double2Float ) import PrelBase import PrelArr import Time (getClockTime, ClockTime(..)) -#else #endif import Char ( isSpace, chr, ord ) \end{code} @@ -267,14 +266,18 @@ stdSplit std@(StdGen s1 _) = (std, unsafePerformIO (mkStdRNG (fromInt s1))) \begin{code} #ifdef __HUGS__ --- TODO: Hugs/setStdGen + setStdGen :: StdGen -> IO () -setStdGen sgen = error "not currently implemented in Stg Hugs" +setStdGen sgen = writeIORef theStdGen sgen --- TODO: Hugs/getStdGen getStdGen :: IO StdGen -getStdGen = error "not currently implemented in Stg Hugs" +getStdGen = readIORef theStdGen + +theStdGen :: IORef StdGen +theStdGen = primRunST (newIORef (createStdGen 0)) + #else + global_rng :: MutableVar RealWorld StdGen global_rng = unsafePerformIO $ do rng <- mkStdRNG 0 @@ -285,6 +288,7 @@ setStdGen sgen = stToIO (writeVar global_rng sgen) getStdGen :: IO StdGen getStdGen = stToIO (readVar global_rng) + #endif