Skip to content

Commit

Permalink
seed fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Nov 12, 2024
1 parent 30714e5 commit 186b769
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/MadsHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down

0 comments on commit 186b769

Please sign in to comment.