A stable RNG for tests: request for feed-back

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.

7 Likes

Version 1.0 is now released, StableRNGs commits to stability :slight_smile:

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

12 Likes

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.

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> 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 doing something like that, with a lengthy discussion if you are interested with some background.

4 Likes