Skip to content

Commit 207fe49

Browse files
committed
Add mkStdGen64. Fixes #141
1 parent 5e1d5bb commit 207fe49

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# 1.3.0
22

3-
* Add `uniformListRM`, `uniformList`, `uniformListR`, `uniforms` and `uniformRs`: [#154](https://github.com/haskell/random/pull/154)
3+
* Add `mkStdGen64`: [#155](https://github.com/haskell/random/pull/155)
4+
* Add `uniformListRM`, `uniformList`, `uniformListR`, `uniforms` and `uniformRs`:
5+
[#154](https://github.com/haskell/random/pull/154)
46
* Add compatibility with recently added `ByteArray` to `base`:
57
[#153](https://github.com/haskell/random/pull/153)
68
* Switch to using `ByteArray` for type class implementation instead of

src/System/Random.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module System.Random
5252
-- ** Standard pseudo-random number generator
5353
, StdGen
5454
, mkStdGen
55+
, mkStdGen64
5556
, initStdGen
5657

5758
-- ** Global standard pseudo-random number generator

src/System/Random/Internal.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module System.Random.Internal
3737
-- ** Standard pseudo-random number generator
3838
, StdGen(..)
3939
, mkStdGen
40+
, mkStdGen64
4041
, theStdGen
4142

4243
-- * Monadic adapters for pure pseudo-random number generators
@@ -882,6 +883,16 @@ instance RandomGen SM32.SMGen where
882883
mkStdGen :: Int -> StdGen
883884
mkStdGen = StdGen . SM.mkSMGen . fromIntegral
884885

886+
-- | Constructs a 'StdGen' deterministically from a `Word64` seed.
887+
--
888+
-- The difference between `mkStdGen` is that `mkStdGen64` will work the same on 64-bit and
889+
-- 32-bit architectures, while the former can only use 32-bit of information for
890+
-- initializing the psuedo-random number generator on 32-bit operating systems
891+
--
892+
-- @since 1.3.0
893+
mkStdGen64 :: Word64 -> StdGen
894+
mkStdGen64 = StdGen . SM.mkSMGen
895+
885896
-- | Global mutable veriable with `StdGen`
886897
theStdGen :: IORef StdGen
887898
theStdGen = unsafePerformIO $ SM.initSMGen >>= newIORef . StdGen

0 commit comments

Comments
 (0)