diff --git a/CHANGES b/CHANGES index 011318cd83..a8d1a6d020 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,13 @@ +5.1.0-dev.144 | 2022-06-30 13:37:40 -0700 + + * Optimize 64 bit random number generation (Johanna Amann) + + rand64bit called random 4 times to generate one 64 bit number. There is + no reason to do this - random() is basically guaranteed to return a 32 + bit number. + + This also adds a static check to make sure that it does. + 5.1.0-dev.142 | 2022-06-30 12:27:42 -0700 * Remove other general deprecations (Tim Wojtulewicz, Corelight) diff --git a/VERSION b/VERSION index 57c16528df..c998faa288 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.1.0-dev.142 +5.1.0-dev.144 diff --git a/src/util.cc b/src/util.cc index 8e8cce8fda..843b04a092 100644 --- a/src/util.cc +++ b/src/util.cc @@ -544,8 +544,9 @@ uint64_t rand64bit() uint64_t base = 0; int i; - for ( i = 1; i <= 4; ++i ) - base = (base << 16) | detail::random_number(); + static_assert(RAND_MAX == 2147483647); // 2^32-1 + for ( i = 1; i <= 2; ++i ) + base = (base << 32) | detail::random_number(); return base; }