Add zeek::max_random() & fix misuse of RAND_MAX w/ zeek::random_number()

In deterministic mode, RAND_MAX is not related to the result of
zeek::random_number() (formerly bro_random()), but some logic was
using RAND_MAX as indication of the possible range of values.  The
new zeek::max_random() will give the correct upper-bound regardless
of whether deterministic-mode is used.
This commit is contained in:
Jon Siwek 2020-07-22 09:57:56 -07:00
parent bde38893ce
commit d486af06b1
6 changed files with 24 additions and 9 deletions

View file

@ -48,7 +48,7 @@ std::string Foo::RandomString(const int len)
// zeek::random_number() is not thread-safe; as we are only using one simultaneous thread
// here, this should not matter in this case. If this test ever starts showing
// random errors, this might be the culprit.
s[i] = values[zeek::random_number() / (RAND_MAX / sizeof(values))];
s[i] = values[zeek::random_number() / (zeek::max_random() / sizeof(values))];
return s;
}