mwc-random 0.9.0.0 → 0.10.0.0
raw patch · 3 files changed
+40/−20 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ System.Random.MWC: fromSeed :: Seed -> Vector Word32
+ System.Random.MWC: toSeed :: Vector v Word32 => v Word32 -> Seed
Files
- README.markdown +5/−5
- System/Random/MWC.hs +28/−8
- mwc-random.cabal +7/−7
README.markdown view
@@ -31,15 +31,15 @@ # Get involved! Please report bugs via the-[bitbucket issue tracker](http://bitbucket.org/bos/mwc-random).+[github issue tracker](http://github.com/bos/mwc-random). -Master [Mercurial repository](http://bitbucket.org/bos/mwc-random):+Master git [git repository](http://github.com/bos/mwc-random): -* `hg clone http://bitbucket.org/bos/mwc-random`+* `git clone git://github.com/bos/mwc-random.git` -There's also a [git mirror](http://github.com/bos/mwc-random):+There's also a [Mercurial mirror](http://bitbucket.org/bos/mwc-random): -* `git clone git://github.com/bos/mwc-random.git`+* `hg clone http://bitbucket.org/bos/mwc-random` (You can create and contribute changes using either Mercurial or git.)
System/Random/MWC.hs view
@@ -24,6 +24,8 @@ , GenIO , GenST , Seed+ , fromSeed+ , toSeed , Variate(..) -- * Other distributions , normal@@ -287,13 +289,23 @@ -- 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.+--+-- If a seed contains exactly 258 elements last two elements are used+-- to set generator state. It's to ensure that @gen' == gen@+--+-- > gen' <- initialize . fromSeed =<< save initialize :: (PrimMonad m, Vector v Word32) => v Word32 -> m (Gen (PrimState m)) initialize seed = do q <- M.unsafeNew 258 fill q- M.unsafeWrite q ioff 255- M.unsafeWrite q coff 362436+ if fini == 258+ then do+ M.unsafeWrite q ioff $ G.unsafeIndex seed ioff .&. 255+ M.unsafeWrite q coff $ G.unsafeIndex seed coff+ else do+ M.unsafeWrite q ioff 255+ M.unsafeWrite q coff 362436 return (Gen q) where fill q = go 0 where go i | i == 256 = return ()@@ -307,9 +319,20 @@ {-# INLINE initialize #-} -- | An immutable snapshot of the state of a 'Gen'.-newtype Seed = Seed (I.Vector Word32)+newtype Seed = Seed { + -- | Convert seed into vector.+ fromSeed :: I.Vector Word32 + } deriving (Eq, Show, Typeable) +-- | Convert vector to 'Seed'. It acts similarily to 'initialize' and+-- will accept any vector. If you want to pass seed immediately to+-- restore you better call initialize directly since following law holds:+--+-- > restore (toSeed v) = initialize v+toSeed :: (Vector v Word32) => v Word32 -> Seed+toSeed v = Seed $ I.create $ do { Gen q <- initialize v; return q }+ -- Safe version of unsafeFreeze. -- NOTE: vector-0.7 will provide function `freeze' with same -- functionality. This function shall be removed when support for@@ -325,6 +348,7 @@ save (Gen q) = Seed `liftM` safeFreeze q {-# INLINE save #-} +-- NOTE: with vector-0.7 all code could be replaced with `clone' -- | Create a new 'Gen' that mirrors the state of a saved 'Seed'. restore :: PrimMonad m => Seed -> m (Gen (PrimState m)) restore (Seed s) = M.unsafeNew n >>= fill@@ -482,11 +506,7 @@ -- but it may be more convenient to use in some situations. uniformVector :: (PrimMonad m, Variate a, Vector v a) => Gen (PrimState m) -> Int -> m (v a)-uniformVector gen n = do- mu <- GM.unsafeNew n- let go !i | i < n = uniform gen >>= GM.unsafeWrite mu i >> go (i+1)- | otherwise = unsafeFreeze mu- go 0+uniformVector gen n = G.replicateM n (uniform gen) {-# INLINE uniformVector #-} data T = T {-# UNPACK #-} !Double {-# UNPACK #-} !Double
mwc-random.cabal view
@@ -1,5 +1,5 @@ name: mwc-random-version: 0.9.0.0+version: 0.10.0.0 synopsis: Fast, high quality pseudo random number generation description: This package contains code for generating high quality random@@ -16,8 +16,8 @@ distributions. license: BSD3 license-file: LICENSE-homepage: https://bitbucket.org/bos/mwc-random-bug-reports: https://bitbucket.org/bos/mwc-random/issues+homepage: https://github.com/bos/mwc-random+bug-reports: https://github.com/bos/mwc-random/issues author: Bryan O'Sullivan <bos@serpentine.com> maintainer: Bryan O'Sullivan <bos@serpentine.com> copyright: 2009, 2010, 2011 Bryan O'Sullivan@@ -50,9 +50,9 @@ ghc-options: -fwarn-tabs source-repository head- type: mercurial- location: https://bitbucket.org/bos/mwc-random--source-repository head type: git location: git://github.com/bos/mwc-random++source-repository head+ type: mercurial+ location: https://bitbucket.org/bos/mwc-random