Assertions

PortfolioOptimisers.resolve_rng — Function
resolve_rng(rng::Random.AbstractRNG, seed::Option{<:Integer})

Resolve the random number generator to draw from, for an optional seed.

A seed gives a fresh, private generator. It is a copy of rng that Random.seed! reseeds with seed. A seeded estimator is thus reproducible, and it does not reseed the task-global generator that the caller can also use. The default rng is Random.default_rng(), which is a shared object, and a reseed of it removes the randomness from the other draws of the caller with no message. When seed is nothing, the function returns rng unchanged.

The function copies rng before it seeds it, and does not construct a fixed generator type such as Random.Xoshiro(seed). The copy keeps the generator object of the caller unchanged, and it keeps the type of that generator. A portable generator from the caller, such as StableRNGs.StableRNG, thus gives the same stream as Random.seed!(rng, seed) gave in place. The draws are the same as the draws of the old in-place seed. The only difference is that the stream of the caller does not change.

Arguments

  • rng: The fallback random number generator. The function returns it unchanged when seed is nothing.
  • seed: The optional seed. When it is set, the function returns a private Random.seed!(copy(rng), seed), and does not change rng.

Algorithm

  1. Return rng unchanged when seed is nothing, so that the caller's generator is the generator to draw from.
  2. Otherwise copy rng, reseed the copy with seed, and return the copy. The function never mutates the caller's own generator.

Returns

  • Random.AbstractRNG: The generator to draw from.

Related

source