From 2af50329f42f049f4ebbaacdaf38ee042e8cebed Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 19 Mar 2026 13:36:08 -1000 Subject: [PATCH] Document design trade-off for state==0 reseed --- esphome/core/helpers.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index f01c97e359..dc8e865d78 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -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(&splitmix32_state), sizeof(splitmix32_state)); }