From 4815b890a7657b54228bd3d50287a1589ec85fd8 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 20 Jul 2023 08:52:59 +0200 Subject: [PATCH] Add a way to reset multiple global random seeds --- src/utils/rand.jl | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/utils/rand.jl b/src/utils/rand.jl index 181041c0e49d..73a87f56aedc 100644 --- a/src/utils/rand.jl +++ b/src/utils/rand.jl @@ -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 @@ -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