Skip to content

Cleanup #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions System/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
module System.Random
(

-- $intro

-- * Random number generators

#ifdef ENABLE_SPLITTABLEGEN
Expand Down Expand Up @@ -255,7 +253,7 @@ The function 'mkStdGen' provides an alternative way of producing an initial
generator, by mapping an 'Int' into a generator. Again, distinct arguments
should be likely to produce distinct generators.
-}
mkStdGen :: Int -> StdGen -- why not Integer ?
mkStdGen :: Int -> StdGen -- Haskell 98 report demands mkStdGen takes an Int.
mkStdGen s = mkStdGen32 $ fromIntegral s

{-
Expand All @@ -272,9 +270,6 @@ mkStdGen32 sMaybeNegative = StdGen (s1+1) (s2+1)
(q, s1) = s `divMod` 2147483562
s2 = q `mod` 2147483398

createStdGen :: Integer -> StdGen
createStdGen s = mkStdGen32 $ fromIntegral s

{- |
With a source of random number supply in hand, the 'Random' class allows the
programmer to extract random values of a variety of types.
Expand Down Expand Up @@ -327,8 +322,7 @@ class Random a where

-- | Produce an infinite list-equivalent of random values.
{-# INLINE buildRandoms #-}
buildRandoms :: RandomGen g
=> (a -> as -> as) -- ^ E.g. '(:)' but subject to fusion
buildRandoms :: (a -> as -> as) -- ^ E.g. '(:)' but subject to fusion
-> (g -> (a,g)) -- ^ E.g. 'random'
-> g -- ^ A 'RandomGen' instance
-> as
Expand Down Expand Up @@ -399,7 +393,7 @@ instance Random Bool where
random g = randomR (minBound,maxBound) g

{-# INLINE randomRFloating #-}
randomRFloating :: (Fractional a, Num a, Ord a, Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomRFloating :: (Fractional a, Ord a, Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomRFloating (l,h) g
| l>h = randomRFloating (h,l) g
| otherwise = let (coef,g') = random g in
Expand Down Expand Up @@ -448,12 +442,6 @@ instance Random CDouble where
-- random rng = case random rng of
-- (x,rng') -> (realToFrac (x::Double), rng')

mkStdRNG :: Integer -> IO StdGen
mkStdRNG o = do
ct <- getCPUTime
(sec, psec) <- getTime
return (createStdGen (sec * 12345 + psec + ct + o))

randomBounded :: (RandomGen g, Random a, Bounded a) => g -> (a, g)
randomBounded = randomR (minBound, maxBound)

Expand Down Expand Up @@ -564,8 +552,9 @@ getStdGen = readIORef theStdGen

theStdGen :: IORef StdGen
theStdGen = unsafePerformIO $ do
rng <- mkStdRNG 0
newIORef rng
(sec, psec) <- getTime
ct <- getCPUTime
newIORef $ mkStdGen32 $ fromInteger (sec * 12345 + psec + ct)

-- |Applies 'split' to the current global random generator,
-- updates it with one of the results, and returns the other.
Expand Down