Skip to content

Commit

Permalink
Add a way to reset multiple global random seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jul 20, 2023
1 parent b5c051e commit 4815b89
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/utils/rand.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# global seed value for oscar to allow creating deterministic random number
# global seed value for OSCAR to allow creating deterministic random number
# generators
# we initialize this here with a random value as well to allow use during
# precompilation
Expand Down Expand Up @@ -33,3 +33,35 @@ be set to a fixed value with `Oscar.set_seed!` as it is done in `runtests.jl`.
"""
get_seeded_rng() = return MersenneTwister([get_seed()])


"""
seed_global!(s::Integer)
Reset the random seed for many global RNGs used by OSCAR. Currently that includes:
- the default Julia random source, `Random.default_rng()`
- the default GAP random source `GlobalMersenneTwister`
- the legacy GAP random source `GlobalRandomSource`
In the future this should also reset the random seeds for Singular, Polymake
and possibly other components used in OSCAR.
```jldoctest
julia> Oscar.seed_global!(1234)
julia> rand(1:1000)
326
julia> GAP.Globals.Random(1,1000)
749
```
"""
seed_global!(s::Integer) = seed_global!(UInt32(s))

function seed_global!(s::UInt32)
Random.seed!(s)

GAP.Globals.Reset(GAP.Globals.GlobalRandomSource, GAP.Obj(s))
GAP.Globals.Reset(GAP.Globals.GlobalMersenneTwister, GAP.Obj(s))

return nothing
end

0 comments on commit 4815b89

Please sign in to comment.