Skip to content

Commit

Permalink
Addition of initStdGen. Fix #103
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Sep 7, 2021
1 parent e75c2ed commit faa7b73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.2.1

* Addition of `initStdGen`

# 1.2.0

1. Breaking change which mostly maintains backwards compatibility, see
Expand Down
14 changes: 12 additions & 2 deletions src/System/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module System.Random
-- ** Standard pseudo-random number generator
, StdGen
, mkStdGen
, initStdGen

-- ** Global standard pseudo-random number generator
-- $globalstdgen
Expand Down Expand Up @@ -312,17 +313,26 @@ instance Random Double where
-- We return 1 - uniformDouble01M here for backwards compatibility with
-- v1.2.0. Just return the result of uniformDouble01M in the next major
-- version.
random g = runStateGen g (\gen -> (1 -) <$> uniformDouble01M gen)
random g = runStateGen g (fmap (1 -) . uniformDouble01M)
{-# INLINE random #-}
instance Random Float where
randomR r g = runStateGen g (uniformRM r)
{-# INLINE randomR #-}
-- We return 1 - uniformFloat01M here for backwards compatibility with
-- v1.2.0. Just return the result of uniformFloat01M in the next major
-- version.
random g = runStateGen g (\gen -> (1 -) <$> uniformFloat01M gen)
random g = runStateGen g (fmap (1 -) . uniformFloat01M)
{-# INLINE random #-}



-- | Initialize 'StdGen' using entropy available on the system (time, ...)
--
-- @since 1.2.1
initStdGen :: MonadIO m => m StdGen
initStdGen = liftIO (StdGen <$> SM.initSMGen)


-------------------------------------------------------------------------------
-- Global pseudo-random number generator
-------------------------------------------------------------------------------
Expand Down

0 comments on commit faa7b73

Please sign in to comment.