Skip to content
Snippets Groups Projects
Commit b3f0c71b authored by sof's avatar sof
Browse files

[project @ 1999-05-05 10:39:25 by sof]

Improved the splitting of the std. generator
parent 6bef2efe
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@ instance Read StdGen where
readsPrec p = \ r ->
case try_read r of
r@[_] -> r
_ -> [(unsafePerformIO mkStdRNG,r)] -- because it shouldn't ever fail.
_ -> [(unsafePerformIO (mkStdRNG 0), r)] -- because it shouldn't ever fail.
where
try_read r = do
(s1, r1) <- readDec (dropWhile isSpace r)
......@@ -155,11 +155,11 @@ instance Random Float where
\begin{code}
mkStdRNG :: IO StdGen
mkStdRNG = do
mkStdRNG :: Integer -> IO StdGen
mkStdRNG o = do
ct <- getCPUTime
(TOD sec _) <- getClockTime
return (createStdGen (sec * 12345 + ct))
return (createStdGen (sec * 12345 + ct + o))
randomIvalInteger :: (RandomGen g, Num a) => (Integer, Integer) -> g -> (a, g)
randomIvalInteger (l,h) rng
......@@ -209,17 +209,18 @@ rand1 (StdGen s1 s2) = (z', StdGen s1'' s2'')
s2'' = if s2' < 0 then s2' + 2147483399 else s2'
splitStdGen :: StdGen -> (StdGen, StdGen)
splitStdGen std@(StdGen s1 s2) = (std, StdGen new_s1 new_s2)
splitStdGen std@(StdGen s1 s2) = (std, unsafePerformIO (mkStdRNG (fromInt s1)))
{- StdGen new_s1 new_s2
where
-- simple in the extreme..
new_s1
| s1 == 2147483562 = 1
| otherwise = s1 + 1
| s2 == 2147483562 = 1
| otherwise = s2 + 1
new_s2
| s2 == 1 = 2147483398
| otherwise = s2 - 1
| s1 == 1 = 2147483398
| otherwise = s1 - 1
-}
\end{code}
......@@ -228,7 +229,7 @@ splitStdGen std@(StdGen s1 s2) = (std, StdGen new_s1 new_s2)
\begin{code}
global_rng :: MutableVar RealWorld StdGen
global_rng = unsafePerformIO $ do
rng <- mkStdRNG
rng <- mkStdRNG 0
stToIO (newVar rng)
setStdGen :: StdGen -> IO ()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment