# Generating random numbers in Julia in different machines

**URL:** https://discourse.julialang.org/t/generating-random-numbers-in-julia-in-different-machines/107589
**Category:** General Usage
**Created:** [December 13, 2023, 10:30pm UTC](https://discourse.julialang.org/t/generating-random-numbers-in-julia-in-different-machines/107589 "2023-12-13T22:30:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)
#### Post date: [December 13, 2023, 10:30pm UTC](https://discourse.julialang.org/t/generating-random-numbers-in-julia-in-different-machines/107589/1 "2023-12-13T22:30:11Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

### Author: ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)
#### Post date: [December 13, 2023, 10:42pm UTC](https://discourse.julialang.org/t/generating-random-numbers-in-julia-in-different-machines/107589/2 "2023-12-13T22:42:43Z")

</div>

You might take a look at [`StableRNGs.jl`](https://github.com/JuliaRandom/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.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [December 13, 2023, 10:50pm UTC](https://discourse.julialang.org/t/generating-random-numbers-in-julia-in-different-machines/107589/3 "2023-12-13T22:50:24Z")

</div>

> [@mikmoore](#):
>
> consistent across hardware when the Julia version is identical.

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.
