# A stable RNG for tests: request for feed-back

**URL:** <https://discourse.julialang.org/t/a-stable-rng-for-tests-request-for-feed-back/38195>\
**Category:** Package Announcements\
**Created:** [April 25, 2020, 3:14pm UTC](https://discourse.julialang.org/t/a-stable-rng-for-tests-request-for-feed-back/38195 "2020-04-25T15:14:28Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [April 30, 2020, 11:26am UTC](https://discourse.julialang.org/t/a-stable-rng-for-tests-request-for-feed-back/38195/21 "2020-04-30T11:26:32Z")

</div>

`StableRNGs` is now registered, I invite package maintainers to try it out!

I will also suggest this option next time I open issues to packages whose test break because of a change of streams in `Random`.

After a couple of months without reported problems, I will tag version 1.0. By then, reviews of the code, comments on the API and discussions (here or in a github issue) are very welcome.

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [September 28, 2020, 7:05pm UTC](https://discourse.julialang.org/t/a-stable-rng-for-tests-request-for-feed-back/38195/22 "2020-09-28T19:05:10Z")

</div>

Version 1.0 is now released, `StableRNGs` commits to stability 🙂

Compared to the last pre-1.0 version, there is essentially no breaking change, except that `LehmerRNG` is no more exported. It was already documented to _not_ be part of the API (only `StableRNG` is), so not exporting it reflects this; the reason is to allow re-using this name in the 1.x timeframe, depending on how this package evolves).

Also, the URL changed to [GitHub - JuliaRandom/StableRNGs.jl: A Julia RNG with stable streams](https://github.com/JuliaRandom/StableRNGs.jl)

---

<div class="post-metadata">

**Author:** ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Post date:** [August 22, 2021, 12:51pm UTC](https://discourse.julialang.org/t/a-stable-rng-for-tests-request-for-feed-back/38195/23 "2021-08-22T12:51:02Z")

</div>

It would be great if `StableRNGs` could take over on the global `RNG`. So the user won’t need to use `rand(rng, ...)` and `randn(rng, ...)`, etc… for each low level call.

I am not not sure if it should be a feature of the package or it might be something which require a change in Julia.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 22, 2021, 2:44pm UTC](https://discourse.julialang.org/t/a-stable-rng-for-tests-request-for-feed-back/38195/24 "2021-08-22T14:44:16Z")

</div>

I think the that it is best to be explicit about the RNG in all code (except possibly for interactive usage of very high-level functions). This is not special to `rand` etc, just a specific instance of the generic advice about globals.

Technically the issue is that

```julia
julia> isconst(Random, :GLOBAL_RNG)
true

```

so you cannot just replace it.

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [August 22, 2021, 3:54pm UTC](https://discourse.julialang.org/t/a-stable-rng-for-tests-request-for-feed-back/38195/25 "2021-08-22T15:54:29Z")

</div>

> [@Tamas\_Papp](#):
>
> Technically the issue is that
> 
> ```julia
> julia> isconst(Random, :GLOBAL_RNG)
> true
> 
> ```
> 
> so you cannot just replace it.

In recent Julia versions, `GLOBAL_RNG` does exist only for backward compatibility (even though `GLOBAL_RNG` was never documented and part of the public API, but packages were using it).

Currently, a hack is technically possible to have a particular RNG become the default one, although it will probably not work in all cases, and in particular in threaded contexts if no specific care is taken: `Random.default_rng() = StableRNG(0)`. But any guarantee (if any existed) is broken if you do that.

As a side note, there was a [pull request](https://github.com/JuliaLang/julia/pull/23205) doing something like that, with a lengthy discussion if you are interested with some background.

[Previous page](https://discourse.julialang.org/t/a-stable-rng-for-tests-request-for-feed-back/38195.md?page=1)
