2026-04-02 16:30:33 +02:00
|
|
|
/**
|
|
|
|
|
* @file RandomGenerator.hpp
|
|
|
|
|
* @brief Random numbers for Monte Carlo (Gaussian draws).
|
|
|
|
|
*/
|
2026-03-08 10:15:23 +01:00
|
|
|
|
|
|
|
|
#ifndef QUANTENGINE_RANDOMGENERATOR_HPP
|
|
|
|
|
#define QUANTENGINE_RANDOMGENERATOR_HPP
|
|
|
|
|
#include <random>
|
|
|
|
|
|
2026-04-02 16:30:33 +02:00
|
|
|
/** @brief Interface for standard normal variates. */
|
2026-03-08 10:15:23 +01:00
|
|
|
class RandomGenerator {
|
|
|
|
|
public:
|
|
|
|
|
RandomGenerator() = default;
|
|
|
|
|
virtual ~RandomGenerator() = default;
|
|
|
|
|
virtual double nextGaussian() = 0;
|
|
|
|
|
virtual std::vector<double> nextGaussianVector(std::size_t n) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-02 16:30:33 +02:00
|
|
|
/** @brief @c std::mt19937 with normal distribution. */
|
2026-03-08 10:15:23 +01:00
|
|
|
class MersenneTwister : public RandomGenerator {
|
|
|
|
|
public:
|
|
|
|
|
MersenneTwister() = default;
|
|
|
|
|
double nextGaussian() override;
|
|
|
|
|
std::vector<double> nextGaussianVector(std::size_t n) override;
|
|
|
|
|
private:
|
|
|
|
|
std::mt19937 generator_;
|
|
|
|
|
std::normal_distribution<> distr_ {0.0, 1.0};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif //QUANTENGINE_RANDOMGENERATOR_HPP
|