packages feed

mwc-random 0.8.0.2 → 0.8.0.3

raw patch · 4 files changed

+91/−68 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

− README
@@ -1,45 +0,0 @@-Efficient, general purpose pseudo-random number generation-------------------------------------------------------------This package provides the System.Random.MWC module, a Haskell library-for generating high-quality pseudo-random numbers in a space- and-time-efficient way.---Performance--------------This library has been carefully optimised for high performance.  To-obtain the best runtime efficiency, it is imperative to compile-libraries and applications that use this library using a high level of-optimisation.--Suggested GHC options:--  -O -fvia-C -funbox-strict-fields--To illustrate, here are the times (in seconds) to generate and sum 250-million random Word32 values, on a laptop with a 2.4GHz Core2 Duo-P8600 processor, running Fedora 11 and GHC 6.10.3:--  no flags   200+-  -O           1.249-  -O -fvia-C   0.991--As the numbers above suggest, compiling without optimisation will-yield unacceptable performance.---Get involved!----------------Please feel welcome to contribute new code or bug fixes.  You can-fetch the source repository from here:--http://bitbucket.org/bos/mwc-random---Authors----------Bryan O'Sullivan <bos@serpentine.com>
+ README.markdown view
@@ -0,0 +1,50 @@+# Efficient, general purpose pseudo-random number generation++This package provides the System.Random.MWC module, a Haskell library+for generating high-quality pseudo-random numbers in a space- and+time-efficient way.+++# Performance++This library has been carefully optimised for high performance.  To+obtain the best runtime efficiency, it is imperative to compile+libraries and applications that use this library using a high level of+optimisation.++Suggested GHC options:++    -O -fvia-C -funbox-strict-fields++To illustrate, here are the times (in seconds) to generate and sum 250+million random Word32 values, on a laptop with a 2.4GHz Core2 Duo+P8600 processor, running Fedora 11 and GHC 6.10.3:++    no flags   200++    -O           1.249+    -O -fvia-C   0.991++As the numbers above suggest, compiling without optimisation will+yield unacceptable performance.+++# Get involved!++Please report bugs via the+[bitbucket issue tracker](http://bitbucket.org/bos/mwc-random).++Master [Mercurial repository](http://bitbucket.org/bos/mwc-random):++* `hg clone http://bitbucket.org/bos/mwc-random`++There's also a [git mirror](http://github.com/bos/mwc-random):++* `git clone git://github.com/bos/mwc-random.git`++(You can create and contribute changes using either Mercurial or git.)+++# Authors++This library is written and maintained by Bryan O'Sullivan,+<bos@serpentine.com>.
System/Random/MWC.hs view
@@ -238,8 +238,8 @@     {-# INLINE uniformR #-}  wordsTo64Bit :: Integral a => Word32 -> Word32 -> a-wordsTo64Bit a b =-    fromIntegral ((fromIntegral a `shiftL` 32) .|. fromIntegral b)+wordsTo64Bit x y =+    fromIntegral ((fromIntegral x `shiftL` 32) .|. fromIntegral y) {-# INLINE wordsTo64Bit #-}  wordToBool :: Word32 -> Bool@@ -254,13 +254,13 @@ {-# INLINE wordToFloat #-}  wordsToDouble :: Word32 -> Word32 -> Double-wordsToDouble x y  = (fromIntegral a * m_inv_32 + (0.5 + m_inv_53) +-                     fromIntegral (b .&. 0xFFFFF) * m_inv_52) +wordsToDouble x y  = (fromIntegral u * m_inv_32 + (0.5 + m_inv_53) ++                     fromIntegral (v .&. 0xFFFFF) * m_inv_52)      where m_inv_52 = 2.220446049250313080847263336181640625e-16           m_inv_53 = 1.1102230246251565404236316680908203125e-16           m_inv_32 = 2.3283064365386962890625e-10-          a        = fromIntegral x :: Int32-          b        = fromIntegral y :: Int32+          u        = fromIntegral x :: Int32+          v        = fromIntegral y :: Int32 {-# INLINE wordsToDouble #-}  -- | State of the pseudo-random number generator.@@ -393,18 +393,26 @@ nextIndex i = fromIntegral j     where j = fromIntegral (i+1) :: Word8 +a :: Word64+a = 1540315826+ uniformWord32 :: PrimMonad m => Gen (PrimState m) -> m Word32 uniformWord32 (Gen q) = do-  let a = 809430660 :: Word64   i  <- nextIndex `liftM` M.unsafeRead q ioff   c  <- fromIntegral `liftM` M.unsafeRead q coff   qi <- fromIntegral `liftM` M.unsafeRead q i-  let t   = a * qi + c-      t32 = fromIntegral t-  M.unsafeWrite q i t32+  let t  = a * qi + c+      c' = fromIntegral (t `shiftR` 32)+      x  = fromIntegral t + c'+      x_lt_c = x < c'+      x'  | x_lt_c    = x + 1+          | otherwise = x+      c'' | x_lt_c    = c' + 1+          | otherwise = c'+  M.unsafeWrite q i x'   M.unsafeWrite q ioff (fromIntegral i)-  M.unsafeWrite q coff (fromIntegral (t `shiftR` 32))-  return t32+  M.unsafeWrite q coff (fromIntegral c'')+  return x' {-# INLINE uniformWord32 #-}  uniform1 :: PrimMonad m => (Word32 -> a) -> Gen (PrimState m) -> m a@@ -415,22 +423,32 @@  uniform2 :: PrimMonad m => (Word32 -> Word32 -> a) -> Gen (PrimState m) -> m a uniform2 f (Gen q) = do-  let a = 809430660 :: Word64   i  <- nextIndex `liftM` M.unsafeRead q ioff   let j = nextIndex i   c  <- fromIntegral `liftM` M.unsafeRead q coff   qi <- fromIntegral `liftM` M.unsafeRead q i   qj <- fromIntegral `liftM` M.unsafeRead q j   let t   = a * qi + c-      t32 = fromIntegral t-      c'  = t `shiftR` 32-      u   = a * qj + c'-      u32 = fromIntegral u-  M.unsafeWrite q i t32-  M.unsafeWrite q j u32+      c'  = fromIntegral (t `shiftR` 32)+      x   = fromIntegral t + c'+      x_lt_c = x < c'+      x'  | x_lt_c    = x + 1+          | otherwise = x+      c'' | x_lt_c    = c' + 1+          | otherwise = c'+      u   = a * qj + fromIntegral c''+      d'  = fromIntegral (u `shiftR` 32)+      y   = fromIntegral u + d'+      y_lt_d = y < d'+      y'  | y_lt_d    = y + 1+          | otherwise = y+      d'' | y_lt_d    = d' + 1+          | otherwise = d'+  M.unsafeWrite q i x'+  M.unsafeWrite q j y'   M.unsafeWrite q ioff (fromIntegral j)-  M.unsafeWrite q coff (fromIntegral (u `shiftR` 32))-  return $! f t32 u32+  M.unsafeWrite q coff (fromIntegral d'')+  return $! f x' y' {-# INLINE uniform2 #-}  -- Type family for fixed size integrals. For signed data types it's
mwc-random.cabal view
@@ -1,5 +1,5 @@ name:           mwc-random-version:        0.8.0.2+version:        0.8.0.3 synopsis:       Fast, high quality pseudo random number generation description:   This package contains code for generating high quality random@@ -25,7 +25,7 @@ build-type:     Simple cabal-version:  >= 1.6 extra-source-files:-  README+  README.markdown   benchmarks/Benchmark.hs   benchmarks/Quickie.hs