diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ee59069..bf717705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # 1.3.0 -* Add `uniformListRM`, `uniformList`, `uniformListR`, `uniforms` and `uniformRs`: [#154](https://github.com/haskell/random/pull/154) +* Add `mkStdGen64`: [#155](https://github.com/haskell/random/pull/155) +* Add `uniformListRM`, `uniformList`, `uniformListR`, `uniforms` and `uniformRs`: + [#154](https://github.com/haskell/random/pull/154) * Add compatibility with recently added `ByteArray` to `base`: [#153](https://github.com/haskell/random/pull/153) * Switch to using `ByteArray` for type class implementation instead of diff --git a/src/System/Random.hs b/src/System/Random.hs index a21a27c8..9bbc2422 100644 --- a/src/System/Random.hs +++ b/src/System/Random.hs @@ -52,6 +52,7 @@ module System.Random -- ** Standard pseudo-random number generator , StdGen , mkStdGen + , mkStdGen64 , initStdGen -- ** Global standard pseudo-random number generator @@ -113,7 +114,7 @@ import qualified System.Random.SplitMix as SM -- -- >>> :{ -- let rolls :: RandomGen g => Int -> g -> [Word] --- rolls n = take n . unfoldr (Just . uniformR (1, 6)) +-- rolls n = fst . uniformListR n (1, 6) -- pureGen = mkStdGen 137 -- in -- rolls 10 pureGen :: [Word] @@ -125,7 +126,7 @@ import qualified System.Random.SplitMix as SM -- -- >>> :{ -- let rollsM :: StatefulGen g m => Int -> g -> m [Word] --- rollsM n = replicateM n . uniformRM (1, 6) +-- rollsM n = uniformListRM n (1, 6) -- pureGen = mkStdGen 137 -- in -- runStateGen_ pureGen (rollsM 10) :: [Word] diff --git a/src/System/Random/Internal.hs b/src/System/Random/Internal.hs index 20b5b47d..e7c6354f 100644 --- a/src/System/Random/Internal.hs +++ b/src/System/Random/Internal.hs @@ -37,6 +37,7 @@ module System.Random.Internal -- ** Standard pseudo-random number generator , StdGen(..) , mkStdGen + , mkStdGen64 , theStdGen -- * Monadic adapters for pure pseudo-random number generators @@ -882,6 +883,16 @@ instance RandomGen SM32.SMGen where mkStdGen :: Int -> StdGen mkStdGen = StdGen . SM.mkSMGen . fromIntegral +-- | Constructs a 'StdGen' deterministically from a `Word64` seed. +-- +-- The difference between `mkStdGen` is that `mkStdGen64` will work the same on 64-bit and +-- 32-bit architectures, while the former can only use 32-bit of information for +-- initializing the psuedo-random number generator on 32-bit operating systems +-- +-- @since 1.3.0 +mkStdGen64 :: Word64 -> StdGen +mkStdGen64 = StdGen . SM.mkSMGen + -- | Global mutable veriable with `StdGen` theStdGen :: IORef StdGen theStdGen = unsafePerformIO $ SM.initSMGen >>= newIORef . StdGen