[project @ 1999-11-22 12:12:09 by sewardj]
authorsewardj <unknown>
Mon, 22 Nov 1999 12:12:09 +0000 (12:12 +0000)
committersewardj <unknown>
Mon, 22 Nov 1999 12:12:09 +0000 (12:12 +0000)
Implement Random.setStdGen and Random.getStdGen for Hugs.

ghc/lib/std/Random.lhs

index 25b4752..9bf845e 100644 (file)
@@ -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