Randomness and reproducible results / unit tests

You can use functions in arguments, so it can be just

function myAlgorithm(; rng = StableRNG(rand(1:typemax(Int64))))

But since argument rand uses global random generator anyway, I prefer to use

function myAlgorithm(; rng = Random.GLOBAL_RNG)

Passing rng instead of seed is better, because it gives more flexibility.

1 Like