Langmuir
Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LangmuirCore::Random Class Reference

A class to generate random numbers. More...

#include <rand.h>

Public Member Functions

 Random (quint64 seed=0, QObject *parent=0)
 Random. More...
 
 ~Random ()
 Destroy objects. More...
 
quint64 seed ()
 Get the seed that was used. More...
 
void seed (quint64 seed)
 seed the generator (again) More...
 
double random ()
 Generate a random double from the uniform distribution [0, 1]. More...
 
double range (const double low=0.0, const double high=1.0)
 Generate a random double from the uniform distribution [low, high]. More...
 
double normal (const double mean, const double sigma)
 Generate a random double from the normal distribution. More...
 
int integer (const int low=0, const int high=1)
 Generate a random int from the uniform distribution [low, high]. More...
 
bool metropolis (double energyChange, double inversekT)
 Randomly choose yes using a Boltzmann factor. More...
 
bool metropolisWithCoupling (double energyChange, double inversekT, double coupling)
 Randomly choose yes using a Boltzmann factor and coupling constant. More...
 
bool chooseYes (double percent)
 Randomly choose yes a percent of the time. More...
 
bool chooseNo (double percent)
 Randomly choose no a percent of the time. More...
 

Private Attributes

boost::mt19937 * twister
 The underlying random number generator. More...
 
boost::variate_generator
< boost::mt19937
&, boost::uniform_01< double > > * 
generator01
 The underlying generator coupled to the uniform distribution on [0,1]. More...
 
quint64 m_seed
 The seed used to start the generator. More...
 

Friends

QDataStream & operator<< (QDataStream &stream, Random &random)
 Output the random state to a QDataStream Possibly Broken. More...
 
QDataStream & operator>> (QDataStream &stream, Random &random)
 Load the random state from a QDataStream Possibly Broken. More...
 
QTextStream & operator<< (QTextStream &stream, Random &random)
 Output the random state to a QTextStream Possibly Broken. More...
 
QTextStream & operator>> (QTextStream &stream, Random &random)
 Load the random state from a QTextStream Possibly Broken. More...
 
std::ostream & operator<< (std::ostream &stream, Random &random)
 Output the random state to a std::ostream. More...
 
std::istream & operator>> (std::istream &stream, Random &random)
 Load the random state from a std::istream. More...
 

Detailed Description

A class to generate random numbers.

Constructor & Destructor Documentation

LangmuirCore::Random::Random ( quint64  seed = 0,
QObject *  parent = 0 
)

Random.

Parameters
seedmakes the generator deterministic
  • seed == 0 uses the current clock time
parentobject this belongs to
LangmuirCore::Random::~Random ( )

Destroy objects.

Member Function Documentation

bool LangmuirCore::Random::chooseNo ( double  percent)

Randomly choose no a percent of the time.

bool LangmuirCore::Random::chooseYes ( double  percent)

Randomly choose yes a percent of the time.

int LangmuirCore::Random::integer ( const int  low = 0,
const int  high = 1 
)

Generate a random int from the uniform distribution [low, high].

bool LangmuirCore::Random::metropolis ( double  energyChange,
double  inversekT 
)

Randomly choose yes using a Boltzmann factor.

Parameters
energyChangechange in energy when going from initial to final state
inversekTdecay constant in exponential
bool LangmuirCore::Random::metropolisWithCoupling ( double  energyChange,
double  inversekT,
double  coupling 
)

Randomly choose yes using a Boltzmann factor and coupling constant.

Parameters
energyChangechange in energy when going from initial to final state
inversekTdecay constant in exponential
couplingalters acceptance probability
  • if energy < 0 : chooses yes coupling * Boltzmann factor percent of the time
  • if energy > 0 : chooses yes 1 - coupling percent of the time
double LangmuirCore::Random::normal ( const double  mean,
const double  sigma 
)

Generate a random double from the normal distribution.

Parameters
meanaverage value of the normal distribution sampled
sigmastandard deviation of the normal distribution sampled
double LangmuirCore::Random::random ( )

Generate a random double from the uniform distribution [0, 1].

double LangmuirCore::Random::range ( const double  low = 0.0,
const double  high = 1.0 
)

Generate a random double from the uniform distribution [low, high].

quint64 LangmuirCore::Random::seed ( )

Get the seed that was used.

void LangmuirCore::Random::seed ( quint64  seed)

seed the generator (again)

If seed == 0 is used, then the generator does not use the current time. This is different than the constructor Random.

Friends And Related Function Documentation

QDataStream& operator<< ( QDataStream &  stream,
Random random 
)
friend

Output the random state to a QDataStream Possibly Broken.

Warning
This may not quite be working correctly
QTextStream& operator<< ( QTextStream &  stream,
Random random 
)
friend

Output the random state to a QTextStream Possibly Broken.

Warning
This may not quite be working correctly
std::ostream& operator<< ( std::ostream &  stream,
Random random 
)
friend

Output the random state to a std::ostream.

QDataStream& operator>> ( QDataStream &  stream,
Random random 
)
friend

Load the random state from a QDataStream Possibly Broken.

Warning
This may not quite be working correctly
QTextStream& operator>> ( QTextStream &  stream,
Random random 
)
friend

Load the random state from a QTextStream Possibly Broken.

Warning
This may not quite be working correctly
std::istream& operator>> ( std::istream &  stream,
Random random 
)
friend

Load the random state from a std::istream.

Member Data Documentation

boost::variate_generator<boost::mt19937&, boost::uniform_01<double> >* LangmuirCore::Random::generator01
private

The underlying generator coupled to the uniform distribution on [0,1].

quint64 LangmuirCore::Random::m_seed
private

The seed used to start the generator.

boost::mt19937* LangmuirCore::Random::twister
private

The underlying random number generator.


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