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

**URL:** https://discourse.julialang.org/t/why-does-julia-1-6-5-and-1-7-1-generate-differnent-random-values-using-the-same-seed/84482
**Category:** Optimization (Mathematical)
**Tags:** question, probability
**Created:** [July 19, 2022, 5:43pm UTC](https://discourse.julialang.org/t/why-does-julia-1-6-5-and-1-7-1-generate-differnent-random-values-using-the-same-seed/84482 "2022-07-19T17:43:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![etorkia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/etorkia/32/11677_2.png) [@etorkia](https://discourse.julialang.org/u/etorkia)
#### Post date: [July 19, 2022, 5:43pm UTC](https://discourse.julialang.org/t/why-does-julia-1-6-5-and-1-7-1-generate-differnent-random-values-using-the-same-seed/84482/1 "2022-07-19T17:43:53Z")

</div>

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

 ![Screenshot JuliaRand](https://global.discourse-cdn.com/julialang/original/3X/0/0/0021e189ae8c4a8b8cea520be38329fe729e391d.png)

Any thoughts? Thanks 🙂

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [July 19, 2022, 5:48pm UTC](https://discourse.julialang.org/t/why-does-julia-1-6-5-and-1-7-1-generate-differnent-random-values-using-the-same-seed/84482/2 "2022-07-19T17:48:23Z")

</div>

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](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.

> **[GitHub - JuliaRandom/StableRNGs.jl: A Julia RNG with stable streams](https://github.com/JuliaRandom/StableRNGs.jl)**
>
> A Julia RNG with stable streams. Contribute to JuliaRandom/StableRNGs.jl development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![etorkia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/etorkia/32/11677_2.png) [@etorkia](https://discourse.julialang.org/u/etorkia)
#### Post date: [July 19, 2022, 5:58pm UTC](https://discourse.julialang.org/t/why-does-julia-1-6-5-and-1-7-1-generate-differnent-random-values-using-the-same-seed/84482/4 "2022-07-19T17:58:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![etorkia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/etorkia/32/11677_2.png) [@etorkia](https://discourse.julialang.org/u/etorkia)
#### Post date: [July 19, 2022, 6:54pm UTC](https://discourse.julialang.org/t/why-does-julia-1-6-5-and-1-7-1-generate-differnent-random-values-using-the-same-seed/84482/5 "2022-07-19T18:54:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [July 19, 2022, 9:02pm UTC](https://discourse.julialang.org/t/why-does-julia-1-6-5-and-1-7-1-generate-differnent-random-values-using-the-same-seed/84482/6 "2022-07-19T21:02:11Z")

</div>

> [@etorkia](#):
>
> and I will never be able to run Documenter.jl with this kind of craziness.

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.
