On Stackoverflow there is a post showing how to save the current state of the base random number generator, so that one can go back and produce the same set of random numbers from a set point that is already so many draws in (ie it is not a simple set the seed response).
Base.Random.GLOBAL_RNG.seed = rng_state.seed
Base.Random.GLOBAL_RNG.state = rng_state.state
Base.Random.GLOBAL_RNG.vals = rng_state.vals
Base.Random.GLOBAL_RNG.idx = rng_state.idx
rs = deepcopy(Base.Random.GLOBAL_RNG)
This does not work for distributions such as Beta and Gamma which utilise the StatsFuns package random number generator instead of the Base one.
I’ve tried to write a function similar to the one above but without success. Can anyone please help (so r1 is identical to r2) in code below - the deepcopy fails so almost certain the function will fail too).
StatsFuns.Random.GLOBAL_RNG.seed = rng_state.seed
StatsFuns.Random.GLOBAL_RNG.state = rng_state.state
StatsFuns.Random.GLOBAL_RNG.vals = rng_state.vals
StatsFuns.Random.GLOBAL_RNG.idx = rng_state.idx
rs = deepcopy(StatsFuns.Random.GLOBAL_RNG)
r1 = rand(Gamma(3,11),5)
r2 = rand(Gamma(3,11),5)