pcg-random 0.1.3.3 → 0.1.3.4
raw patch · 3 files changed
+17/−7 lines, 3 files
Files
- CHANGELOG.md +4/−0
- pcg-random.cabal +1/−1
- src/System/Random/PCG/Pure.hs +12/−6
CHANGELOG.md view
@@ -1,3 +1,7 @@+### 0.1.3.4++* Fix byte array bugs in System.Random.PCG.Pure+ ### 0.1.3.3 * Added System.Random.PCG.Pure module.
pcg-random.cabal view
@@ -1,5 +1,5 @@ name: pcg-random-version: 0.1.3.3+version: 0.1.3.4 synopsis: Haskell bindings to the PCG random number generator. description: PCG is a family of simple fast space-efficient statistically good
src/System/Random/PCG/Pure.hs view
@@ -107,8 +107,11 @@ poke ptr (SetSeq x y) = poke ptr' x >> pokeElemOff ptr' 1 y where ptr' = castPtr ptr {-# INLINE poke #-}- peek ptr = SetSeq <$> peek ptr' <*> peekElemOff ptr' 1- where ptr' = castPtr ptr+ peek ptr = do+ let ptr' = castPtr ptr+ s <- peek ptr'+ inc <- peekElemOff ptr' 1+ return $ SetSeq s inc {-# INLINE peek #-} -- | Fixed seed.@@ -199,7 +202,10 @@ -- | Save the state of a 'Gen' in a 'Seed'. save :: PrimMonad m => Gen (PrimState m) -> m SetSeq-save (G a) = SetSeq <$> readByteArray a 0 <*> readByteArray a 8+save (G a) = do+ s <- readByteArray a 0+ inc <- readByteArray a 1+ return $ SetSeq s inc {-# INLINE save #-} -- | Restore a 'Gen' from a 'Seed'.@@ -207,7 +213,7 @@ restore (SetSeq s inc) = do a <- newByteArray 16 writeByteArray a 0 s- writeByteArray a 8 inc+ writeByteArray a 1 inc return $! G a {-# INLINE restore #-} @@ -277,14 +283,14 @@ instance (PrimMonad m, s ~ PrimState m) => Generator (Gen s) m where uniform1 f (G a) = do s <- readByteArray a 0- inc <- readByteArray a 8+ inc <- readByteArray a 1 writeByteArray a 0 $! s * multiplier + inc return $! f (output s) {-# INLINE uniform1 #-} uniform2 f (G a) = do s <- readByteArray a 0- inc <- readByteArray a 8+ inc <- readByteArray a 1 let !s' = s * multiplier + inc writeByteArray a 0 $! s' * multiplier + inc return $! f (output s) (output s')