Newer
Older
Gigg, Martyn Anthony
committed
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include "MantidKernel/MersenneTwister.h"
namespace Mantid
{
namespace Kernel
{
//------------------------------------------------------------------------------
// Public member functions
//------------------------------------------------------------------------------
/**
* Default constructor. Sets the range to [0.0,1.0]
*/
MersenneTwister::MersenneTwister() :
m_generator(), m_uniform_dist(0.0, 1.0)
{
}
/**
* (Re-)seed the generator
Janik Zikovsky
committed
* @param seedValue :: A seed for the generator
Gigg, Martyn Anthony
committed
*/
Gigg, Martyn Anthony
committed
void MersenneTwister::setSeed(unsigned int seedValue)
Gigg, Martyn Anthony
committed
{
Gigg, Martyn Anthony
committed
// Bug in earlier versions of this implementation meant
Gigg, Martyn Anthony
committed
// that a unsigned int could not be past to the seed function
Gigg, Martyn Anthony
committed
m_generator.seed((boost::mt19937::result_type)seedValue);
Gigg, Martyn Anthony
committed
}
/**
* Sets the range of the subsequent calls to next()
Janik Zikovsky
committed
* @param start :: The lowest value a call to next() will produce
* @param end :: The largest value a call to next() will produce
Gigg, Martyn Anthony
committed
*/
void MersenneTwister::setRange(double start, double end)
{
m_uniform_dist = uniform_double(start,end);
}
/**
* Returns the next number in the pseudo-random sequence generated by
* the Mersenne Twister 19937 algorithm.
* @returns The next number in the pseudo-random sequence
*/
double MersenneTwister::next()
{
/// A variate generator to combine a random number generator with a distribution
uniform_generator uniform_rand(m_generator, m_uniform_dist);
// There is no reason why this call shouldn't be considered const
return uniform_rand();
}
}
}