Why does Julia 1.6.5 and 1.7.1 generate differnent random values using the same seed?

I found that if you start a fresh session in both 1.6.5. and 1.7.1 you get different results. I found this glitch while running doctests… and I will never be able to run Documenter.jl with this kind of craziness.

using Random
rng = MersenneTwister(1)
Random.seed!(1)
rand(2)

Try it and you will see that doctesting is impossible if you use rand()s

Any thoughts? Thanks :slight_smile:

This is documented. The random number generator is not guaranteed to produce the same values between minor versions.

https://docs.julialang.org/en/v1/stdlib/Random/#Reproducibility

If you would like a stable stream of random values for a particular seed, try StableRNGs.jl.

Thanks for the packages. The doc seems to address the the whole doctest thing. I will try it out.

Turns out I was not passing the rng argument to the rand(). The correct way to seed would be rand(rng, 5)

Documenter.jl has filter expressions for the docstrings, which allow you to filter out parts of outputs. Only relying on doctests for functionality is quite brittle, especially with a fixed seed - if possible, I’d recommend testing properties you’d expect of the output in your testsuite instead.