From 186b7694b7312e6155a3af89237010487506eb97 Mon Sep 17 00:00:00 2001 From: monty Date: Mon, 11 Nov 2024 17:50:16 -0700 Subject: [PATCH] seed fixes --- src/MadsHelpers.jl | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/MadsHelpers.jl b/src/MadsHelpers.jl index cc570e5c..df455b96 100644 --- a/src/MadsHelpers.jl +++ b/src/MadsHelpers.jl @@ -515,36 +515,25 @@ function getseed() return Random.GLOBAL_SEED.s0 end -function seedrng(f=nothing) +function seedrng(f::Union{Nothing,Random.AbstractRNG,DataType}=nothing) if isnothing(f) - if isdefined(Random, :TaskLocalRNG) - f = Random.TaskLocalRNG - else - f = Random.MersenneTwister - end - end - if isdefined(Random, :TaskLocalRNG) && f == Random.TaskLocalRNG - global rng = f() - else - global rng = f() + f = Random.TaskLocalRNG end + global rng = f() + return nothing end -function seed!(s, f=nothing) +function seed!(s, f::Union{Nothing,Random.AbstractRNG,DataType}=nothing) if isnothing(f) - if isdefined(Random, :TaskLocalRNG) - f = Random.TaskLocalRNG - else - f = Random.MersenneTwister - end + f = Random.TaskLocalRNG end - if isdefined(Random, :TaskLocalRNG) && f == Random.TaskLocalRNG + if f == Random.MersenneTwister + global rng = f(s) + else # Random.TaskLocalRNG global rng = f() Random.seed!(s) - else - isdefined(Random, :set_global_seed!) && Random.set_global_seed!(s) - global rng = f(s) end + return nothing end """