How to change the default RNG for a given script?

I know I can pass RNG to many (all?) stochastic functions, and that StableRNG is slow, but is there a way I can set at the beginning of my model something like:

random_seed = 123          # from a config file
Random.GLOBAL_RNG = StableRNG(123)`

?

This doesn’t work as Random.GLOBAL_RNG is a constant.

No, unless you want to edit Random.jl, but you can seed!(123), or you just have to pass the rng object down the call chain.

1 Like

And if it’s too tedious to pass down the call chain, you could make your RNG a global const and just access it at the call sites. Although if it’s not then passing it down is a tad nicer.

And faster: