mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
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:
parent
bde38893ce
commit
d486af06b1
6 changed files with 24 additions and 9 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue