Mantid
Loading...
Searching...
No Matches
MersenneTwister.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//------------------------------------------------------------------------------
10// Includes
11//------------------------------------------------------------------------------
13
14#include <memory>
15#include <random>
16
17namespace Mantid {
18namespace Kernel {
24class MANTID_KERNEL_DLL MersenneTwister final : public PseudoRandomNumberGenerator {
25
26public:
30 MersenneTwister(const double start, const double end);
33 explicit MersenneTwister(const size_t seedValue);
35 MersenneTwister(const size_t seedValue, const double start, const double end);
36
39
41 void setSeed(const size_t seedValue) override;
43 void setRange(const double start, const double end) override;
46 inline double nextValue() override { return uniformRealDistribution(m_engine); }
48 inline double nextValue(double start, double end) override {
49 return std::uniform_real_distribution<double>(start, end)(m_engine);
50 }
52 int nextInt(int start, int end) override;
54 void restart() override;
56 void save() override;
59 void restore() override;
61 double min() const override { return m_start; }
63 double max() const override { return m_end; }
64
65private:
67 std::mt19937 m_engine;
69 std::uniform_real_distribution<double> uniformRealDistribution;
71 double m_start;
73 double m_end;
75 std::mt19937::result_type m_seed;
78 std::unique_ptr<std::mt19937> m_savedEngine;
79};
80} // namespace Kernel
81} // namespace Mantid
This implements the the Mersenne Twister 19937 pseudo-random number generator algorithm as a specialz...
std::uniform_real_distribution< double > uniformRealDistribution
Uniform Real distribution.
double m_end
Maximum in range.
MersenneTwister & operator=(const MersenneTwister &)=delete
MersenneTwister(const MersenneTwister &)=delete
double m_start
Minimum in range.
double nextValue() override
Generate the next random number in the sequence within the given range default range.
double min() const override
Return the minimum value of the range.
std::mt19937::result_type m_seed
The current seed.
std::mt19937 m_engine
The engine.
double max() const override
Return the maximum value of the range.
std::unique_ptr< std::mt19937 > m_savedEngine
A generator that will take the value when save is requested.
double nextValue(double start, double end) override
Generate the next random number in the sequence within the given range.
Defines a 1D pseudo-random number generator, i.e.
Helper class which provides the Collimation Length for SANS instruments.