Difference in Random numbers between 1.5 & 1.6

The HISTORY.md file does not show any changes to Random number generation between v1.5 and v1.6, but I still see different numbers generated with the same seed/RNG:

Julia 1.5.4:

julia> VERSION
v"1.5.4"

julia> using Random

julia> observed=rand(MersenneTwister(1234), 0:100, 5)
5-element Array{Int64,1}:
 10
 37
 74
 12
 95

Julia 1.6.3:

julia> VERSION
v"1.6.3"

julia> using Random

julia> observed=rand(MersenneTwister(1234), 0:100, 5)
5-element Vector{Int64}:
 48
 60
 94
 60
 12

Could anyone help explain what’s happening?

Thank you.

The TLDR is don’t assume random numbers will be the same between versions. If you want random numbers that are the same between versions use StableRNGs.

2 Likes

This is documented and expected behavior.

As a heads up: julia 1.7 will switch from MersenneTwister to Xoshiro (a much faster and easier to parallelize pseudo RNG), as well as have a different RNG object per task, which will also change the stream of random numbers.

Thanks. I knew about the change in 1.7, but we’re planning a move to 1.6 since it will be the next LTS. I didn’t expect 1.6 to be different, but I understand why.

If you’re planning such a large version jump, also note that due to performance improvements and improvements to numerical accuracy, exact bitpatterns for floating point results are not guaranteed between versions.

If there was such a guarantee, almost any change to floating point algorithms would be breaking.

1 Like

I didn’t think 1.5.4 → 1.6.3 was a big jump, it’s just the next available version even though it is a minor version jump.

FWIW, I have over 70000 unit tests and the only one that fails after changing versions is the one that assumed random would be the same.

3 Likes