diff --git a/src/util.cc b/src/util.cc index ff488226c3..61fe2df55d 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1078,7 +1078,7 @@ static void bro_srandom(unsigned int seed, bool deterministic) srandom(seed); } -void bro_srandom(unsigned int seed) +void zeek::seed_random(unsigned int seed) { if ( bro_rand_determistic ) bro_rand_state = seed == 0 ? 1 : seed; @@ -1086,6 +1086,11 @@ void bro_srandom(unsigned int seed) srandom(seed); } +void bro_srandom(unsigned int seed) + { + zeek::seed_random(seed); + } + void init_random_seed(const char* read_file, const char* write_file, bool use_empty_seeds) { diff --git a/src/util.h b/src/util.h index c699204915..d848a43078 100644 --- a/src/util.h +++ b/src/util.h @@ -230,6 +230,7 @@ long int bro_random(); // Calls the system srandom() function with the given seed if not running // in deterministic mode, else it updates the state of the deterministic PRNG. +[[deprecated("Remove in v4.1. Use zeek::seed_random()")]] void bro_srandom(unsigned int seed); extern uint64_t rand64bit(); @@ -614,4 +615,12 @@ long int random_number(); */ long int max_random(); +/** + * Wrapper for system srandom() in the default case, but when running in + * deterministic mode, updates the state used for calling zeek::prng() + * inside of zeek::random_number(). + * @param seed Value to use for initializing the PRNG. + */ +void seed_random(unsigned int seed); + } // namespace zeek diff --git a/src/zeek.bif b/src/zeek.bif index 1d09e4bddf..0de446fbbc 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -946,7 +946,7 @@ function rand%(max: count%): count ## provided by the OS. function srand%(seed: count%): any %{ - bro_srandom(seed); + zeek::seed_random(seed); return nullptr; %}