[project @ 2000-01-23 09:55:17 by andy]
[ghc-hetmet.git] / ghc / lib / std / Random.lhs
index 25b4752..0064315 100644 (file)
@@ -29,18 +29,18 @@ module Random
        ) where
 
 #ifndef __HUGS__
-import CPUTime (getCPUTime)
-import PrelST
-import PrelRead
-import PrelShow
-import PrelNum         -- So we get fromInt, toInt
-import PrelIOBase
-import PrelNumExtra ( float2Double, double2Float )
-import PrelBase
-import PrelArr
-import Time (getClockTime, ClockTime(..))
-#else
+import PrelGHC         ( RealWorld )
+import PrelNum         ( fromInt )
+import PrelShow                ( showSignedInt, showSpace )
+import PrelRead                ( readDec )
+import PrelIOBase      ( unsafePerformIO, stToIO )
+import PrelArr         ( MutableVar, newVar, readVar, writeVar )
+import PrelReal                ( toInt )
+import CPUTime         ( getCPUTime )
+import PrelFloat       ( float2Double, double2Float )
+import Time            ( getClockTime, ClockTime(..) )
 #endif
+
 import Char ( isSpace, chr, ord )
 \end{code}
 
@@ -242,7 +242,6 @@ stdNext (StdGen s1 s2) = (z', StdGen s1'' s2'')
                s2'  = 40692 * (s2 - k' * 52774) - k' * 3791
                s2'' = if s2' < 0 then s2' + 2147483399 else s2'
 
-#ifdef __HUGS__
 stdSplit            :: StdGen -> (StdGen, StdGen)
 stdSplit std@(StdGen s1 s2)
                      = (left, right)
@@ -258,23 +257,23 @@ stdSplit std@(StdGen s1 s2)
                                | otherwise        = s2 - 1
 
                         StdGen t1 t2 = snd (next std)
-#else
-stdSplit :: StdGen -> (StdGen, StdGen)
-stdSplit std@(StdGen s1 _) = (std, unsafePerformIO (mkStdRNG (fromInt s1)))
-#endif 
 \end{code}
 
 
 \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 +284,7 @@ setStdGen sgen = stToIO (writeVar global_rng sgen)
 
 getStdGen :: IO StdGen
 getStdGen = stToIO (readVar global_rng)
+
 #endif