Fix doctests
This addresses https://github.com/commercialhaskell/stackage/issues/7493.
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:
https://github.com/haskell/random/blob/623cf518c6bc4c1de6a4d59b43c3ae37fcb22a35/src/System/Random.hs#L647-L650
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.
Are there any release plans, btw? Asking, since Stackage is still stuck on an older doctest version because of this.
Are there any release plans, btw?
@juhp Yes, I am planning on making a release over Christmas break.
In any case, I suspect stackage will be stuck on this for a while, since last time major version of random was released it took stackage almost a year to adopt it (all due tons of speculative upper bounds in downstream packages: https://github.com/commercialhaskell/stackage/issues/5474)
I can try making a patch release of random-1.2.1.3 that drops usage of doctest, in order to unblock doctes. Would that be helpful?
I can try making a patch release of
random-1.2.1.3that drops usage ofdoctest, in order to unblockdoctes. Would that be helpful?
Yes that sounds good if you can, thank you!
For now I try to disable the random testsuite in Stackage Nightly as a workaround hopefully
Yes that sounds good if you can, thank you!
@juhp random-1.2.1.3 that does not depend on doctest is up on Hackage.