Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: RandomSeed with 32 bit in Examples #3860

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstdint>
#include <random>

Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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;
Expand Down
19 changes: 7 additions & 12 deletions Examples/Framework/src/Framework/RandomNumbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading