Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Mantid::Kernel::MersenneTwister Class Referencefinal

This implements the the Mersenne Twister 19937 pseudo-random number generator algorithm as a specialzation of the PseudoRandomNumberGenerator interface. More...

#include <MersenneTwister.h>

Inheritance diagram for Mantid::Kernel::MersenneTwister:
Mantid::Kernel::PseudoRandomNumberGenerator Mantid::Kernel::NDRandomNumberGenerator

Public Member Functions

double max () const override
 Return the maximum value of the range. More...
 
 MersenneTwister ()
 Construct the generator using time stamp for the initial seed. More...
 
 MersenneTwister (const double start, const double end)
 Construct the generator with an initial range and default seed. More...
 
 MersenneTwister (const MersenneTwister &)=delete
 
 MersenneTwister (const size_t seedValue)
 Construct the generator with an initial seed. More...
 
 MersenneTwister (const size_t seedValue, const double start, const double end)
 Construct the generator with an initial seed and range. More...
 
double min () const override
 Return the minimum value of the range. More...
 
int nextInt (int start, int end) override
 Return the next integer in the sequence within the given range. More...
 
double nextValue () override
 Generate the next random number in the sequence within the given range default range. More...
 
double nextValue (double start, double end) override
 Generate the next random number in the sequence within the given range. More...
 
MersenneTwisteroperator= (const MersenneTwister &)=delete
 
void restart () override
 Resets the generator. More...
 
void restore () override
 Restores the generator to the last saved point, or the beginning if nothing has been saved. More...
 
void save () override
 Saves the current state of the generator. More...
 
void setRange (const double start, const double end) override
 Sets the range of the subsequent calls to next. More...
 
void setSeed (const size_t seedValue) override
 Set the random number seed. More...
 
- Public Member Functions inherited from Mantid::Kernel::PseudoRandomNumberGenerator
void generateNextPoint () override
 Generates the next point. More...
 
virtual double max () const =0
 Return the maximum value of the range. More...
 
virtual double min () const =0
 Return the minimum value of the range. More...
 
virtual int nextInt (int start, int end)=0
 Return the next integer in the sequence. More...
 
virtual double nextValue ()=0
 Return the next double in the sequence. More...
 
virtual double nextValue (double start, double end)=0
 Return the next double in the sequence overriding the default range. More...
 
double operator() ()
 Return next random value. More...
 
PseudoRandomNumberGeneratoroperator= (const PseudoRandomNumberGenerator &)=delete
 Disable assignment operator. More...
 
 PseudoRandomNumberGenerator ()
 Default constructor setting the dimension to 1. More...
 
 PseudoRandomNumberGenerator (const PseudoRandomNumberGenerator &)=delete
 Disable copy operator. More...
 
virtual void setRange (const double start, const double end)=0
 Sets the range of the subsequent calls to nextValue;. More...
 
virtual void setSeed (const size_t seedValue)=0
 Set the random number seed. More...
 
- Public Member Functions inherited from Mantid::Kernel::NDRandomNumberGenerator
 NDRandomNumberGenerator ()=delete
 Disable default constructor. More...
 
 NDRandomNumberGenerator (const NDRandomNumberGenerator &)=delete
 Disable copy operator. More...
 
 NDRandomNumberGenerator (const unsigned int ndims)
 Constructor. More...
 
const std::vector< double > & nextPoint ()
 Generate the next set of values that form a point in ND space. More...
 
unsigned int numberOfDimensions () const
 Returns the number of dimensions the point will be generated in, i.e. More...
 
NDRandomNumberGeneratoroperator= (const NDRandomNumberGenerator &)=delete
 Disable assignment operator. More...
 
virtual void restart ()=0
 Restarts the generator from the beginning of the sequence. More...
 
virtual void restore ()=0
 Restores the generator to the last saved point, or the beginning if nothing has been saved. More...
 
virtual void save ()=0
 Saves the current state of the generator. More...
 
virtual ~NDRandomNumberGenerator ()=default
 Virtual destructor to ensure that all inheriting classes have one. More...
 

Private Attributes

double m_end
 Maximum in range. More...
 
std::mt19937 m_engine
 The engine. More...
 
std::unique_ptr< std::mt19937 > m_savedEngine
 A generator that will take the value when save is requested. More...
 
std::mt19937::result_type m_seed
 The current seed. More...
 
double m_start
 Minimum in range. More...
 
std::uniform_real_distribution< double > uniformRealDistribution
 Uniform Real distribution. More...
 

Additional Inherited Members

- Public Types inherited from Mantid::Kernel::PseudoRandomNumberGenerator
using result_type = double
 Result (output) value type. More...
 
- Protected Member Functions inherited from Mantid::Kernel::NDRandomNumberGenerator
void cacheGeneratedValue (const size_t index, const double value)
 Cache a value for a given dimension index, i.e. 0->ND-1. More...
 
void cacheNextPoint (const std::vector< double > &nextPoint)
 Cache the while point in one go. More...
 
virtual void generateNextPoint ()=0
 Generate the next point. Override this in you concrete implementation. More...
 
std::vector< double > & getNextPointCache ()
 Some generators need direct access to the cache. More...
 

Detailed Description

This implements the the Mersenne Twister 19937 pseudo-random number generator algorithm as a specialzation of the PseudoRandomNumberGenerator interface.

Definition at line 24 of file MersenneTwister.h.

Constructor & Destructor Documentation

◆ MersenneTwister() [1/5]

Mantid::Kernel::MersenneTwister::MersenneTwister ( )

Construct the generator using time stamp for the initial seed.

Construct the generator time stamp for the initial seed.

The range is set to [0.0, 1.0]

Definition at line 32 of file MersenneTwister.cpp.

◆ MersenneTwister() [2/5]

Mantid::Kernel::MersenneTwister::MersenneTwister ( const double  start,
const double  end 
)

Construct the generator with an initial range and default seed.

Constructor taking a range.

Parameters
start:: The minimum value a generated number should take
end:: The maximum value a generated number should take

Definition at line 39 of file MersenneTwister.cpp.

◆ MersenneTwister() [3/5]

Mantid::Kernel::MersenneTwister::MersenneTwister ( const size_t  seedValue)
explicit

Construct the generator with an initial seed.

Constructor taking a seed value.

It can be reseeded using setSeed.

Sets the range to [0.0,1.0]

Parameters
seedValue:: The initial seed

Definition at line 26 of file MersenneTwister.cpp.

◆ MersenneTwister() [4/5]

Mantid::Kernel::MersenneTwister::MersenneTwister ( const size_t  seedValue,
const double  start,
const double  end 
)

Construct the generator with an initial seed and range.

Constructor taking a seed value and a range.

Parameters
seedValue:: The initial seed
start:: The minimum value a generated number should take
end:: The maximum value a generated number should take

Definition at line 48 of file MersenneTwister.cpp.

References setSeed().

◆ MersenneTwister() [5/5]

Mantid::Kernel::MersenneTwister::MersenneTwister ( const MersenneTwister )
delete

Member Function Documentation

◆ max()

double Mantid::Kernel::MersenneTwister::max ( ) const
inlineoverridevirtual

Return the maximum value of the range.

Implements Mantid::Kernel::PseudoRandomNumberGenerator.

Definition at line 63 of file MersenneTwister.h.

◆ min()

double Mantid::Kernel::MersenneTwister::min ( ) const
inlineoverridevirtual

Return the minimum value of the range.

Implements Mantid::Kernel::PseudoRandomNumberGenerator.

Definition at line 61 of file MersenneTwister.h.

◆ nextInt()

int Mantid::Kernel::MersenneTwister::nextInt ( int  start,
int  end 
)
overridevirtual

Return the next integer in the sequence within the given range.

Returns the next integer in the pseudo-random sequence generated by the Mersenne Twister 19937 algorithm.

Parameters
startStart of the requested range
endEnd of the requested range
Returns
An integer in the defined range

Implements Mantid::Kernel::PseudoRandomNumberGenerator.

Definition at line 81 of file MersenneTwister.cpp.

References m_engine.

◆ nextValue() [1/2]

double Mantid::Kernel::MersenneTwister::nextValue ( )
inlineoverridevirtual

◆ nextValue() [2/2]

double Mantid::Kernel::MersenneTwister::nextValue ( double  start,
double  end 
)
inlineoverridevirtual

Generate the next random number in the sequence within the given range.

Implements Mantid::Kernel::PseudoRandomNumberGenerator.

Definition at line 48 of file MersenneTwister.h.

◆ operator=()

MersenneTwister & Mantid::Kernel::MersenneTwister::operator= ( const MersenneTwister )
delete

◆ restart()

void Mantid::Kernel::MersenneTwister::restart ( )
overridevirtual

Resets the generator.

Resets the generator using the value given at the last call to setSeed.

Implements Mantid::Kernel::NDRandomNumberGenerator.

Definition at line 88 of file MersenneTwister.cpp.

References m_seed, and setSeed().

Referenced by restore().

◆ restore()

void Mantid::Kernel::MersenneTwister::restore ( )
overridevirtual

Restores the generator to the last saved point, or the beginning if nothing has been saved.

Implements Mantid::Kernel::NDRandomNumberGenerator.

Definition at line 95 of file MersenneTwister.cpp.

References m_engine, m_savedEngine, and restart().

◆ save()

void Mantid::Kernel::MersenneTwister::save ( )
overridevirtual

Saves the current state of the generator.

Implements Mantid::Kernel::NDRandomNumberGenerator.

Definition at line 91 of file MersenneTwister.cpp.

References m_engine, and m_savedEngine.

◆ setRange()

void Mantid::Kernel::MersenneTwister::setRange ( const double  start,
const double  end 
)
overridevirtual

Sets the range of the subsequent calls to next.

Sets the range of the subsequent calls to nextValue()

Parameters
start:: The lowest value a call to nextValue() will produce
end:: The largest value a call to nextValue() will produce

Implements Mantid::Kernel::PseudoRandomNumberGenerator.

Definition at line 68 of file MersenneTwister.cpp.

References m_end, m_start, and uniformRealDistribution.

◆ setSeed()

void Mantid::Kernel::MersenneTwister::setSeed ( const size_t  seedValue)
overridevirtual

Set the random number seed.

(Re-)seed the generator.

This resets the current saved state

Parameters
seedValue:: A seed for the generator

Implements Mantid::Kernel::PseudoRandomNumberGenerator.

Definition at line 57 of file MersenneTwister.cpp.

References m_engine, m_savedEngine, and m_seed.

Referenced by MersenneTwister(), and restart().

Member Data Documentation

◆ m_end

double Mantid::Kernel::MersenneTwister::m_end
private

Maximum in range.

Definition at line 73 of file MersenneTwister.h.

Referenced by setRange().

◆ m_engine

std::mt19937 Mantid::Kernel::MersenneTwister::m_engine
private

The engine.

Definition at line 67 of file MersenneTwister.h.

Referenced by nextInt(), restore(), save(), and setSeed().

◆ m_savedEngine

std::unique_ptr<std::mt19937> Mantid::Kernel::MersenneTwister::m_savedEngine
private

A generator that will take the value when save is requested.

Pointer so that it is only instantiated when required

Definition at line 78 of file MersenneTwister.h.

Referenced by restore(), save(), and setSeed().

◆ m_seed

std::mt19937::result_type Mantid::Kernel::MersenneTwister::m_seed
private

The current seed.

Definition at line 75 of file MersenneTwister.h.

Referenced by restart(), and setSeed().

◆ m_start

double Mantid::Kernel::MersenneTwister::m_start
private

Minimum in range.

Definition at line 71 of file MersenneTwister.h.

Referenced by setRange().

◆ uniformRealDistribution

std::uniform_real_distribution<double> Mantid::Kernel::MersenneTwister::uniformRealDistribution
private

Uniform Real distribution.

Definition at line 69 of file MersenneTwister.h.

Referenced by setRange().


The documentation for this class was generated from the following files: