From 2f25b25c7a8f10ba69afb14601d9412420ca4edc Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Thu, 14 Nov 2024 17:40:48 +0100 Subject: [PATCH] fix: `RandomSeed` with 32 bit in Examples (#3860) Right now we have a 64 bit seed but only use a 32 bit RNG. Here I align them by using 32 bit for both. Discovered in https://github.com/acts-project/acts/pull/3849 --- .../ActsExamples/Framework/RandomNumbers.hpp | 17 +++++------------ .../Framework/src/Framework/RandomNumbers.cpp | 19 +++++++------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/Examples/Framework/include/ActsExamples/Framework/RandomNumbers.hpp b/Examples/Framework/include/ActsExamples/Framework/RandomNumbers.hpp index 6f9f9abbcd6..a94bac778f6 100644 --- a/Examples/Framework/include/ActsExamples/Framework/RandomNumbers.hpp +++ b/Examples/Framework/include/ActsExamples/Framework/RandomNumbers.hpp @@ -6,18 +6,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// -// RandomNumbers.hpp -// ActsExamples -// -// Created by Andreas Salzburger on 17/05/16. -// -// - #pragma once -#include "ActsExamples/Framework/AlgorithmContext.hpp" - #include #include @@ -27,6 +17,9 @@ struct AlgorithmContext; /// The random number generator used in the framework. using RandomEngine = std::mt19937; ///< Mersenne Twister +/// The seed type used in the framework. +using RandomSeed = std::uint32_t; + /// Provide event and algorithm specific random number generator.s /// /// This provides local random number generators, allowing for @@ -41,7 +34,7 @@ using RandomEngine = std::mt19937; ///< Mersenne Twister class RandomNumbers { public: struct Config { - std::uint64_t seed = 1234567890u; ///< random seed + RandomSeed seed = 1234567890u; ///< random seed }; explicit RandomNumbers(const Config& cfg); @@ -59,7 +52,7 @@ class RandomNumbers { /// /// This should only be used in special cases e.g. where a custom /// random engine is used and `spawnGenerator` can not be used. - std::uint64_t generateSeed(const AlgorithmContext& context) const; + RandomSeed generateSeed(const AlgorithmContext& context) const; private: Config m_cfg; diff --git a/Examples/Framework/src/Framework/RandomNumbers.cpp b/Examples/Framework/src/Framework/RandomNumbers.cpp index 5fd0cdcf7d7..4313a5cce77 100644 --- a/Examples/Framework/src/Framework/RandomNumbers.cpp +++ b/Examples/Framework/src/Framework/RandomNumbers.cpp @@ -6,26 +6,21 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// -// RandomNumbers.cpp -// ActsExamples -// -// Created by Andreas Salzburger on 17/05/16. -// -// - #include "ActsExamples/Framework/RandomNumbers.hpp" #include "ActsExamples/Framework/AlgorithmContext.hpp" -ActsExamples::RandomNumbers::RandomNumbers(const Config& cfg) : m_cfg(cfg) {} +namespace ActsExamples { + +RandomNumbers::RandomNumbers(const Config& cfg) : m_cfg(cfg) {} -ActsExamples::RandomEngine ActsExamples::RandomNumbers::spawnGenerator( +RandomEngine RandomNumbers::spawnGenerator( const AlgorithmContext& context) const { return RandomEngine(generateSeed(context)); } -std::uint64_t ActsExamples::RandomNumbers::generateSeed( - const AlgorithmContext& context) const { +RandomSeed RandomNumbers::generateSeed(const AlgorithmContext& context) const { return m_cfg.seed + context.eventNumber; } + +} // namespace ActsExamples