Closed sol closed 1 month ago
Why do the generated random numbers change? I would have thought with a fixed seed we should always get the same random numbers i.e. why this: https://github.com/haskell/random/pull/165/files#diff-fe93ae678c398cfea72ff60186cc2cee27bd752aad99d8fd1ece059c912f0104L645
@idontgetoutmuch I don't think the seed was fixed for those examples before this PR.
Why do the generated random numbers change? I would have thought with a fixed seed we should always get the same random numbers i.e. why this: https://github.com/haskell/random/pull/165/files#diff-fe93ae678c398cfea72ff60186cc2cee27bd752aad99d8fd1ece059c912f0104L645
@idontgetoutmuch That is because that example uses global StdGen, which as comment below example points out, is usually not a very good idea:
In fact we do fix seed for doctests. In module System.Random.Stateful
:
-- $setup
-- >>> import Control.Monad.Primitive
-- >>> import qualified System.Random.MWC as MWC
-- >>> writeIORef theStdGen $ mkStdGen 2021
Maybe cabal doctest executes modules in different order?
Maybe cabal doctest executes modules in different order?
I am sure that is the case. Which is also the reason why I always suggest avoid using the global generator whenever reproducability is important.
This addresses https://github.com/commercialhaskell/stackage/issues/7493.