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 bc92d76 commit 3a9557a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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 @@ -880,6 +881,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 3a9557a

Please sign in to comment.