random icon indicating copy to clipboard operation
random copied to clipboard

Fix doctests

Open sol opened this issue 1 year ago • 4 comments

This addresses https://github.com/commercialhaskell/stackage/issues/7493.

sol avatar Jul 29 '24 00:07 sol

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 avatar Jul 29 '24 08:07 idontgetoutmuch

@idontgetoutmuch I don't think the seed was fixed for those examples before this PR.

sol avatar Jul 29 '24 10:07 sol

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

lehins avatar Jul 29 '24 22:07 lehins

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?

Shimuuar avatar Jul 30 '24 08:07 Shimuuar

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.

lehins avatar Jul 30 '24 17:07 lehins

Are there any release plans, btw? Asking, since Stackage is still stuck on an older doctest version because of this.

juhp avatar Dec 11 '24 08:12 juhp

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?

lehins avatar Dec 11 '24 20:12 lehins

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?

Yes that sounds good if you can, thank you!

juhp avatar Dec 12 '24 05:12 juhp

For now I try to disable the random testsuite in Stackage Nightly as a workaround hopefully

juhp avatar Dec 12 '24 06:12 juhp

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.

lehins avatar Dec 14 '24 20:12 lehins