From 111ed5a01e97a29acd569e697f02f518249005cf Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 25 Jun 2026 16:19:49 +0000 Subject: [PATCH] Replace insecure time-based random seed generation with std::random_device The seed_random function was generating seeds based on the current system time, which is highly predictable and insecure for PRNG usage. This commit replaces the high_resolution_clock with std::random_device to fetch hardware/OS-level entropy, shifting two 32-bit values to properly generate a secure 64-bit seed. Co-authored-by: perim <436583+perim@users.noreply.github.com> --- dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dice.cpp b/dice.cpp index 659912c..38d225a 100644 --- a/dice.cpp +++ b/dice.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -68,10 +69,11 @@ filtered_const_roll_table::filtered_const_roll_table(const std::vector& wei // here so we do not have to include the chrono header in our public header seed seed_random() { + std::random_device rd; uint64_t v; do { - v = static_cast(std::chrono::high_resolution_clock::now().time_since_epoch().count()); + v = (static_cast(rd()) << 32) | rd(); } while (v == 0); return seed(v); }