Mantid
Loading...
Searching...
No Matches
NDPseudoRandomNumberGenerator.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2012 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//------------------------------------------------------------------------------
12#include "MantidKernel/DllConfig.h"
14#ifndef Q_MOC_RUN
15#include <memory>
16#endif
17
18namespace Mantid {
19namespace Kernel {
28template <typename SingleValueGenerator>
30public:
32 NDPseudoRandomNumberGenerator(const unsigned int ndims, const size_t seedValue);
34 NDPseudoRandomNumberGenerator(const unsigned int ndims, const size_t seedValue, const double start, const double end);
35
38
41
44
46 void setSeed(const size_t seedValue);
48 void generateNextPoint() override;
50 void restart() override;
52 void save() override;
55 void restore() override;
56
57private:
59 SingleValueGenerator m_singleValueGen;
60};
61
62//-------------------------------------------------------------------------------------------------------
63// Implementation
64//-------------------------------------------------------------------------------------------------------
65
74template <typename SingleValueGenerator>
76 const size_t seedValue)
77 : NDRandomNumberGenerator(ndims), m_singleValueGen(seedValue) {}
78
90template <typename SingleValueGenerator>
92 const size_t seedValue,
93 const double start, const double end)
94 : NDRandomNumberGenerator(ndims), m_singleValueGen(seedValue, start, end) {}
95
100template <typename SingleValueGenerator>
102 m_singleValueGen.setSeed(seedValue);
103}
104
106template <typename SingleValueGenerator> void NDPseudoRandomNumberGenerator<SingleValueGenerator>::generateNextPoint() {
107 for (unsigned int i = 0; i < numberOfDimensions(); ++i) {
108 this->cacheGeneratedValue(i, m_singleValueGen.nextValue());
109 }
110}
111
115template <typename SingleValueGenerator> void NDPseudoRandomNumberGenerator<SingleValueGenerator>::restart() {
116 m_singleValueGen.restart();
117}
118
120template <typename SingleValueGenerator> void NDPseudoRandomNumberGenerator<SingleValueGenerator>::save() {
121 m_singleValueGen.save();
122}
123
126template <typename SingleValueGenerator> void NDPseudoRandomNumberGenerator<SingleValueGenerator>::restore() {
127 m_singleValueGen.restore();
128}
129} // namespace Kernel
130} // namespace Mantid
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
Defines an ND pseudo-random number generator.
NDPseudoRandomNumberGenerator & operator=(const NDPseudoRandomNumberGenerator &)=delete
Disable assignment operator.
NDPseudoRandomNumberGenerator(const NDPseudoRandomNumberGenerator &)=delete
Disable copy operator.
void generateNextPoint() override
Generates the next ND point.
void setSeed(const size_t seedValue)
Set the random number seed.
SingleValueGenerator m_singleValueGen
The single value generator.
NDPseudoRandomNumberGenerator()=delete
Disable default constructor.
void save() override
Saves the current state of the generator.
void restore() override
Restores the generator to the last saved point, or the beginning if nothing has been saved.
This class defines an interface for N dimensional random number generators.
Helper class which provides the Collimation Length for SANS instruments.