src/core/utils/prng.h

Provides a wrapper around the STL pseudo-random number generator Mersenne Twister. More…

Namespaces

Name
allpix
Helper class to hold support layers for a detector model.

Classes

Name
class allpix::RandomNumberGenerator
Wrapper around the STL’s Mersenne Twister.

Detailed Description

Provides a wrapper around the STL pseudo-random number generator Mersenne Twister.

Copyright: Copyright (c) 2020-2024 CERN and the Allpix Squared authors. This software is distributed under the terms of the MIT License, copied verbatim in the file “LICENSE.md”. In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction. SPDX-License-Identifier: MIT

Source code


#ifndef ALLPIX_PRNG_H
#define ALLPIX_PRNG_H

#include "core/utils/log.h"

#include <random>

namespace allpix {

    class RandomNumberGenerator : public std::mt19937_64 {
    public:

        RandomNumberGenerator& operator=(const RandomNumberGenerator&) = delete;


        RandomNumberGenerator& operator=(RandomNumberGenerator&&) = delete;

        std::uint_fast64_t operator()() {
            // Only copy if we want to log it
            IFLOG(PRNG) {
                auto prn = std::mt19937_64::operator()();
                LOG(PRNG) << "Using random number " << prn;
                return prn;
            }
            else {
                return std::mt19937_64::operator()();
            }
        }
    };
} // namespace allpix

#endif /* ALLPIX_PRNG_H */

Updated on 2025-02-27 at 14:14:46 +0000