packages feed

mwc-random 0.5.1.4 → 0.6.0.0

raw patch · 2 files changed

+37/−23 lines, 2 filesdep −primitivedep ~basePVP ok

version bump matches the API change (PVP)

Dependencies removed: primitive

Dependency ranges changed: base

API changes (from Hackage documentation)

- System.Random.MWC: type GenIO = Gen (PrimState IO)
- System.Random.MWC: type GenST s = Gen (PrimState (ST s))
- System.Random.MWC: create :: (PrimMonad m) => m (Gen (PrimState m))
+ System.Random.MWC: create :: ST s (Gen s)
- System.Random.MWC: initialize :: (PrimMonad m) => Vector Word32 -> m (Gen (PrimState m))
+ System.Random.MWC: initialize :: Vector Word32 -> ST s (Gen s)
- System.Random.MWC: normal :: (PrimMonad m) => Gen (PrimState m) -> m Double
+ System.Random.MWC: normal :: Gen s -> ST s Double
- System.Random.MWC: restore :: (PrimMonad m) => Seed -> m (Gen (PrimState m))
+ System.Random.MWC: restore :: Seed -> ST s (Gen s)
- System.Random.MWC: save :: (PrimMonad m) => Gen (PrimState m) -> m Seed
+ System.Random.MWC: save :: Gen s -> ST s Seed
- System.Random.MWC: uniform :: (Variate a, PrimMonad m) => Gen (PrimState m) -> m a
+ System.Random.MWC: uniform :: (Variate a) => Gen s -> ST s a
- System.Random.MWC: uniformVector :: (PrimMonad m, Variate a) => Gen (PrimState m) -> Int -> m (Vector a)
+ System.Random.MWC: uniformVector :: (Variate a) => Gen s -> Int -> ST s (Vector a)
- System.Random.MWC: withSystemRandom :: (PrimMonad m) => (Gen (PrimState m) -> m a) -> IO a
+ System.Random.MWC: withSystemRandom :: (Gen s -> ST s a) -> IO a

Files

System/Random/MWC.hs view
@@ -21,8 +21,8 @@     (     -- * Types       Gen-    , GenIO-    , GenST+    --, GenIO+    --, GenST     , Seed     , Variate(..)     -- * Other distributions@@ -46,8 +46,8 @@  import Control.Exception (IOException, catch) import Control.Monad (ap, liftM, unless)-import Control.Monad.ST (ST)-import Control.Monad.Primitive (PrimMonad, PrimState, unsafePrimToIO)+import Control.Monad.ST (ST, unsafeSTToIO)+--import Control.Monad.Primitive (PrimMonad, PrimState, unsafePrimToIO) import Data.Bits ((.&.), (.|.), xor) import Data.IORef (atomicModifyIORef, newIORef) import Data.Int (Int8, Int16, Int32, Int64)@@ -95,7 +95,8 @@     -- To generate a 'Float' variate with a range of [0,1), subtract     -- 2**(-33).  To do the same with 'Double' variates, subtract     -- 2**(-53).-    uniform :: (PrimMonad m) => Gen (PrimState m) -> m a+    uniform :: Gen s -> ST s a+    --uniform :: (PrimMonad m) => Gen (PrimState m) -> m a  instance Variate Int8 where     uniform = uniform1 fromIntegral@@ -208,17 +209,18 @@ newtype Gen s = Gen (M.MVector s Word32)  -- | A shorter name for PRNG state in the IO monad.-type GenIO = Gen (PrimState IO)+--type GenIO = Gen (PrimState IO)  -- | A shorter name for PRNG state in the ST monad.-type GenST s = Gen (PrimState (ST s))+--type GenST s = Gen (PrimState (ST s))  ioff, coff :: Int ioff = 256 coff = 257  -- | Create a generator for variates using a fixed seed.-create :: PrimMonad m => m (Gen (PrimState m))+create :: ST s (Gen s)+--create :: PrimMonad m => m (Gen (PrimState m)) create = initialize defaultSeed {-# INLINE create #-} @@ -236,7 +238,8 @@ -- If a seed contains fewer than 256 elements, it is first used -- verbatim, then its elements are 'xor'ed against elements of the -- default seed until 256 elements are reached.-initialize :: PrimMonad m => I.Vector Word32 -> m (Gen (PrimState m))+initialize :: I.Vector Word32 -> ST s (Gen s)+--initialize :: PrimMonad m => I.Vector Word32 -> m (Gen (PrimState m)) initialize seed = do     q <- M.unsafeNew 258     fill q@@ -259,12 +262,14 @@     deriving (Eq, Show, Typeable)  -- | Save the state of a 'Gen', for later use by 'restore'.-save :: PrimMonad m => Gen (PrimState m) -> m Seed+save :: Gen s -> ST s Seed+--save :: PrimMonad m => Gen (PrimState m) -> m Seed save (Gen q) = Seed `liftM` unsafeFreeze q {-# INLINE save #-}  -- | Create a new 'Gen' that mirrors the state of a saved 'Seed'.-restore :: PrimMonad m => Seed -> m (Gen (PrimState m))+restore :: Seed -> ST s (Gen s)+--restore :: PrimMonad m => Seed -> m (Gen (PrimState m)) restore (Seed s) = M.unsafeNew n >>= fill   where fill q = go 0 where           go !i | i >= n    = return $! Gen q@@ -275,13 +280,15 @@ -- | Using the current time as a seed, perform an action that uses a -- random variate generator.  This is a horrible fallback for Windows -- systems.-withTime :: (PrimMonad m) => (Gen (PrimState m) -> m a) -> IO a+withTime :: (Gen s -> ST s a) -> IO a+--withTime :: (PrimMonad m) => (Gen (PrimState m) -> m a) -> IO a withTime act = do   c <- (numerator . (%cpuTimePrecision)) `liftM` getCPUTime   t <- toRational `liftM` getPOSIXTime   let n    = fromIntegral (numerator t) :: Word64       seed = [fromIntegral c, fromIntegral n, fromIntegral (n `shiftR` 32)]-  unsafePrimToIO $ initialize (I.fromList seed) >>= act+  unsafeSTToIO $ initialize (I.fromList seed) >>= act+  --unsafePrimToIO $ initialize (I.fromList seed) >>= act  -- | Seed a PRNG with data from the system's fast source of -- pseudo-random numbers (\"\/dev\/urandom\" on Unix-like systems),@@ -291,7 +298,8 @@ -- Cryptographic API as a source of random numbers (it uses the system -- clock instead). As a result, the sequences it generates may not be -- highly independent.-withSystemRandom :: PrimMonad m => (Gen (PrimState m) -> m a) -> IO a+withSystemRandom :: (Gen s -> ST s a) -> IO a+--withSystemRandom :: PrimMonad m => (Gen (PrimState m) -> m a) -> IO a withSystemRandom act = tryRandom `catch` \(_::IOException) -> do     seen <- atomicModifyIORef warned ((,) True)     unless seen $ do@@ -305,7 +313,8 @@                   nread <- withBinaryFile random ReadMode $                            \h -> hGetBuf h buf nbytes                   peekArray (nread `div` 4) buf-          unsafePrimToIO $ initialize (I.fromList ws) >>= act+          unsafeSTToIO $ initialize (I.fromList ws) >>= act+          --unsafePrimToIO $ initialize (I.fromList ws) >>= act         random = "/dev/urandom"         warned = unsafePerformIO $ newIORef False         {-# NOINLINE warned #-}@@ -324,7 +333,8 @@ nextIndex i = fromIntegral j     where j = fromIntegral (i+1) :: Word8 -uniformWord32 :: PrimMonad m => Gen (PrimState m) -> m Word32+uniformWord32 :: Gen s -> ST s Word32+--uniformWord32 :: PrimMonad m => Gen (PrimState m) -> m Word32 uniformWord32 (Gen q) = do   let a = 809430660 :: Word64   i <- nextIndex `liftM` M.unsafeRead q ioff@@ -338,13 +348,15 @@   return t32 {-# INLINE uniformWord32 #-} -uniform1 :: PrimMonad m => (Word32 -> a) -> Gen (PrimState m) -> m a+uniform1 :: (Word32 -> a) -> Gen s -> ST s a+--uniform1 :: PrimMonad m => (Word32 -> a) -> Gen (PrimState m) -> m a uniform1 f gen = do   i <- uniformWord32 gen   return $! f i {-# INLINE uniform1 #-} -uniform2 :: PrimMonad m => (Word32 -> Word32 -> a) -> Gen (PrimState m) -> m a+uniform2 :: (Word32 -> Word32 -> a) -> Gen s -> ST s a+--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@@ -367,8 +379,9 @@ -- | Generate a vector of pseudo-random variates.  This is not -- necessarily faster than invoking 'uniform' repeatedly in a loop, -- but it may be more convenient to use in some situations.-uniformVector :: (PrimMonad m, Variate a)-             => Gen (PrimState m) -> Int -> m (I.Vector a)+uniformVector :: (Variate a) => Gen s -> Int -> ST s (I.Vector a)+--uniformVector :: (PrimMonad m, Variate a)+--              => Gen (PrimState m) -> Int -> m (I.Vector a) uniformVector gen n = do   mu <- M.unsafeNew n   let go !i | i < n     = uniform gen >>= M.unsafeWrite mu i >> go (i+1)@@ -384,7 +397,8 @@ -- Compared to the ziggurat algorithm usually used, this is slower, -- but generates more independent variates that pass stringent tests -- of randomness.-normal :: PrimMonad m => Gen (PrimState m) -> m Double+normal :: Gen s -> ST s Double+--normal :: PrimMonad m => Gen (PrimState m) -> m Double normal gen = loop   where     loop = do
mwc-random.cabal view
@@ -1,5 +1,5 @@ name:           mwc-random-version:        0.5.1.4+version:        0.6.0.0 synopsis:       Fast, high quality pseudo random number generation description:   This package contains code for generating high quality random@@ -33,7 +33,7 @@     System.Random.MWC   build-depends:     base < 5,-    primitive,+    --primitive,     time,     vector >= 0.5   if impl(ghc >= 6.10)