Generating random numbers in Julia in different machines

Dear all,
I want to generate reproductive random numbers in Julia. I have used the code:

using Random
rng = MersenneTwister(2024);
z =  round.(100 .+ 200*rand(rng),digits=3)

That’s ok, works very well.
However, When I run in another machine, the result is different.

How Can I fix this?
i want to generate the same random numbers, independely of the computer used.

You might take a look at StableRNGs.jl. I’m not certain whether it promises the same values across different hardware, but it might. I skimmed the source code and I didn’t notice anything that looked like it would change across hardware. Note that the generator provided is “lower quality” than the builtin MersenneTwister or Xoshiro, but this isn’t critical for many tasks.

I would have expect that the generation of scalar random variables (i.e., generating values one at a time) to be consistent across hardware when the Julia version is identical. Maybe not for the MersenneTwister (I don’t know its details – maybe it does batch generation that might vary a little with hardware details) but at least for the Xoshiro generator.

2 Likes

The docs warn that different versions can have different implementations, thus give different numbers for the same seed:

Because the precise way in which random numbers are generated is considered an implementation detail, bug fixes and speed improvements may change the stream of numbers that are generated after a version change. Relying on a specific seed or generated stream of numbers during unit testing is thus discouraged - consider testing properties of the methods in question instead.

angeloaliano1, share versioninfo() for the two machines, after redacting some possibly personal file paths.