Skip to content

Commit

Permalink
Add mkStdGen64. Fixes #141
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Nov 26, 2023
1 parent 5e1d5bb commit 207fe49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/System/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module System.Random
-- ** Standard pseudo-random number generator
, StdGen
, mkStdGen
, mkStdGen64
, initStdGen

-- ** Global standard pseudo-random number generator
Expand Down
11 changes: 11 additions & 0 deletions src/System/Random/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 207fe49

Please sign in to comment.