mwc-random 0.7.0.0 → 0.7.0.1
raw patch · 2 files changed
+15/−6 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- System/Random/MWC.hs +14/−5
- mwc-random.cabal +1/−1
System/Random/MWC.hs view
@@ -46,11 +46,11 @@ 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) import Data.Bits ((.&.), (.|.), xor)-import Data.IORef (atomicModifyIORef, newIORef) import Data.Int (Int8, Int16, Int32, Int64)+import Data.IORef (atomicModifyIORef, newIORef) import Data.Ratio ((%), numerator) import Data.Time.Clock.POSIX (getPOSIXTime) import Data.Typeable (Typeable)@@ -61,11 +61,13 @@ import GHC.Base (Int(I#)) import GHC.Word (Word64(W64#), uncheckedShiftL64#, uncheckedShiftRL64#) import Prelude hiding (catch)+import qualified Data.Vector.Generic as G+import qualified Data.Vector.Generic.Mutable as GM+import qualified Data.Vector.Unboxed as I+import qualified Data.Vector.Unboxed.Mutable as M import System.CPUTime (cpuTimePrecision, getCPUTime) import System.IO (IOMode(..), hGetBuf, hPutStrLn, stderr, withBinaryFile) import System.IO.Unsafe (unsafePerformIO)-import qualified Data.Vector.Unboxed as I-import qualified Data.Vector.Unboxed.Mutable as M -- | The class of types for which we can generate uniformly -- distributed random variates.@@ -258,9 +260,16 @@ newtype Seed = Seed (I.Vector Word32) deriving (Eq, Show, Typeable) +-- Safe version of unsafeFreeze.+safeFreeze :: (PrimMonad m, Vector v a) => G.Mutable v (PrimState m) a -> m (v a)+safeFreeze v = do+ v' <- GM.unsafeNew (GM.length v)+ GM.unsafeCopy v' v+ unsafeFreeze v'+ -- | Save the state of a 'Gen', for later use by 'restore'. save :: PrimMonad m => Gen (PrimState m) -> m Seed-save (Gen q) = Seed `liftM` unsafeFreeze q+save (Gen q) = Seed `liftM` safeFreeze q {-# INLINE save #-} -- | Create a new 'Gen' that mirrors the state of a saved 'Seed'.
mwc-random.cabal view
@@ -1,5 +1,5 @@ name: mwc-random-version: 0.7.0.0+version: 0.7.0.1 synopsis: Fast, high quality pseudo random number generation description: This package contains code for generating high quality random