Expose Bro's linear congruence PRNG as utility function.

It was previously not possible to crank the wheel on the PRNG in a
deterministic way without affecting the globally unique seed. The new extra
utility function bro_prng takes a state in the form of a long int and returns
the new PRNG state, now allowing arbitrary code parts to use the random number
functionality.

This commit also fixes a problem in the H3 constructor, which requires use
of multiple seeds. The single seed passed in now serves as seed to crank out as
many value needed using bro_prng.
This commit is contained in:
Matthias Vallentin 2013-06-17 14:02:14 -07:00
parent 79a6a26f9f
commit 9f74064289
3 changed files with 24 additions and 13 deletions

View file

@ -173,9 +173,12 @@ unsigned int initial_seed();
// Returns true if the user explicitly set a seed via init_random_seed();
extern bool have_random_seed();
// A simple linear congruence PRNG. It takes its state as argument and returns
// a new random value, which can serve as state for subsequent calls.
long int bro_prng(long int state);
// Replacement for the system random(), to which is normally falls back
// except when a seed has been given. In that case, we use our own
// predictable PRNG.
// except when a seed has been given. In that case, the function bro_prng.
long int bro_random();
// Calls the system srandom() function with the given seed if not running