From d370444aedbe407b0c09f1cb345d17512a5d3149 Mon Sep 17 00:00:00 2001 From: Davis Mosenkovs Date: Mon, 17 Aug 2026 20:07:02 +0300 Subject: [PATCH] Reseed Dice RNG on every Roll This improves entropy of Dice, especially when triggered by shaking. As a pleasant side effect this also makes the Dice app more like a physical dice - dependent on how it is shaken, but in an unpredictable manner. The monotonic counter xTaskGetTickCount() in the seed should greatly reduce chances of generating the same RNG seed in multiple rolls. --- src/displayapp/screens/Dice.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/displayapp/screens/Dice.cpp b/src/displayapp/screens/Dice.cpp index 302c5f3fb2..4341859812 100644 --- a/src/displayapp/screens/Dice.cpp +++ b/src/displayapp/screens/Dice.cpp @@ -43,12 +43,6 @@ Dice::Dice(Controllers::MotionController& motionController, Controllers::MotorController& motorController, Controllers::Settings& settingsController) : motorController {motorController}, motionController {motionController}, settingsController {settingsController} { - std::seed_seq sseq {static_cast(xTaskGetTickCount()), - static_cast(motionController.X()), - static_cast(motionController.Y()), - static_cast(motionController.Z())}; - gen.seed(sseq); - lv_obj_t* nCounterLabel = MakeLabel(&jetbrains_mono_bold_20, LV_COLOR_WHITE, LV_LABEL_LONG_EXPAND, @@ -155,6 +149,12 @@ void Dice::Refresh() { } void Dice::Roll() { + std::seed_seq sseq {static_cast(xTaskGetTickCount()), + static_cast(motionController.X()), + static_cast(motionController.Y()), + static_cast(motionController.Z())}; + gen.seed(sseq); + uint8_t resultIndividual; uint16_t resultTotal = 0; std::uniform_int_distribution<> distrib(1, dCounter.GetValue());