Document design trade-off for state==0 reseed

This commit is contained in:
J. Nick Koston
2026-03-19 13:36:08 -10:00
parent 1b090e6b95
commit 2af50329f4
+3
View File
@@ -164,6 +164,9 @@ uint32_t fnv1_hash(const char *str) {
static uint32_t splitmix32_state; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
uint32_t random_uint32() {
// State of 0 means unseeded. The state will wrap back to 0 after 2^32 calls,
// triggering one extra random_bytes() call — an acceptable trade-off vs. adding
// a separate bool flag (4 bytes BSS + branch on every call).
if (splitmix32_state == 0) {
random_bytes(reinterpret_cast<uint8_t *>(&splitmix32_state), sizeof(splitmix32_state));
}