Commits

Aleksey Khudyakov committed 71b5c93

implement normal in terms of standard

Comments (0)

Files changed (1)

System/Random/MWC/Distributions.hs

 {-# INLINE normal #-}
 -- We express standard in terms of normal and not other way round
 -- because of bug in GHC. See bug #16 for more details.
-normal m s gen = loop >>= (\x -> return $! m + s * x)
+normal m s gen = do
+  x <- standard gen
+  return $! m + s * x
+
+-- | Generate a normally distributed random variate with zero mean and
+-- unit variance.
+--
+-- The implementation uses Doornik's modified ziggurat algorithm.
+-- Compared to the ziggurat algorithm usually used, this is slower,
+-- but generates more independent variates that pass stringent tests
+-- of randomness.
+standard :: PrimMonad m => Gen (PrimState m) -> m Double
+{-# INLINE standard #-}
+standard gen = loop
   where
     loop = do
       u  <- (subtract 1 . (*2)) `liftM` uniform gen
 {-# NOINLINE ratios #-}
 
 
--- | Generate a normally distributed random variate with zero mean and
--- unit variance.
---
--- The implementation uses Doornik's modified ziggurat algorithm.
--- Compared to the ziggurat algorithm usually used, this is slower,
--- but generates more independent variates that pass stringent tests
--- of randomness.
-standard :: PrimMonad m => Gen (PrimState m) -> m Double
-{-# INLINE standard #-}
-standard = normal 0 1
-
 
 -- | Generate an exponentially distributed random variate.
 exponential :: PrimMonad m