Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
b3f0c71b
Commit
b3f0c71b
authored
May 05, 1999
by
sof
Browse files
[project @ 1999-05-05 10:39:25 by sof]
Improved the splitting of the std. generator
parent
6bef2efe
Changes
1
Hide whitespace changes
Inline
Side-by-side
ghc/lib/std/Random.lhs
View file @
b3f0c71b
...
...
@@ -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
| s
1
== 2147483562 = 1
| otherwise = s
1
+ 1
| s
2
== 2147483562 = 1
| otherwise = s
2
+ 1
new_s2
| s
2
== 1 = 2147483398
| otherwise = s
2
- 1
| s
1
== 1 = 2147483398
| otherwise = s
1
- 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 ()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment