Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

RanNumGen Class Reference

The Random Number Generator class. More...

#include <copy-ocsRanNumGen.hh>

List of all members.

Public Methods

 RanNumGen (string InFileName)
 Class constructor. More...

 ~RanNumGen ()
 Class destructor. More...

void SaveCurrentState (void)
 Saves the current state of the random number generator. More...

void ResetRanNumGen (void)
 Resets the RNG to the state it was in at the beginning of the job or that was saved by a call to RanNumGen::SaveCurrentState.

float GetRanNum (void)
 Returns the next random number in the sequence. More...

float GetRanCosineBiased (double alpha, double beta, double *LikelihoodRatio)
 This method generates a biased sample for importance sampling.

float GetRanSignBiased (double alpha, double *LikelihoodRatio)
float GetRanCosineBiased (double alpha, double *LikelihoodRatio)
float GetGaussianDeviate (void)
 Returns a random sample from a the 1-dimensaional Gaussian distribution with mean 0 and standard deviation 1. More...

void ReadRanSeqParameters (string InFileName)
 Initializes the state of the RNG by reading the state parameters from a file.

void WriteRanSeqParameters (string OutFileName)
 Writes the current state of the RNG to a file. More...


Private Attributes

long idum
long idumStart
long idum2
long idum2Start
long iy
long iyStart
long iv [NTAB]
long ivStart [NTAB]
string ContinuationFileName
 The name of the file to which the current state of the RNG is written.

string RestartFileName
 The name of the file to which the state of the RNG at the start of the current job is written.


Static Private Attributes

const long IM1 = 2147483563
const long IM2 = 2147483399
const double AM = 1.0/2147483563
const long IMM1 = IM1 - 1
const long IA1 = 40014
const long IA2 = 40692
const long IQ1 = 53668
const long IQ2 = 52774
const long IR1 = 12211
const long IR2 = 3791
const int NTAB = 32
const long NDIV = (1+IMM1/NTAB)
const double EPS = 1.2e-7
const double RNMX = 1.0-EPS


Detailed Description

The Random Number Generator class.

The RanNumGen class uses the Random Number Generator (RNG) ran2 from Numerical Recipes in C. A helpful discussion of this random number generator can be found in the book Numerical Recipes in C or online at http://www.nr.com/ . Additional discussion can be found in "Random Number Generation and Monte Carlo Methods" by James E. Gentle (Springer).

The class contains methods that read and write the state of the RNG from and to a file. When running multiple jobs this feature enables the user to either continue along the random sequence from where we left off at the end of the last job or restart the RNG at the point in the sequence where the previous job started. The RNG can also be restarted within a job.

The class also contains methods that are used in importance sampling.


Constructor & Destructor Documentation

RanNumGen::RanNumGen ( string InFileName )
 

Class constructor.

The constructor reads parameters from an input parameter file.

Parameters:
InFileName:   Name of the input parameter file (string)

It does the following:

  1. Reads in OperationMode and initializes state of RNG accordingly.
  2. Writes the current state of the RNG to the file InFileName + ".restart"
  3. Initializes variables which store the state of the RNG at the time the constructor is called for possible later use by the method ResetRanNumGen()
The possible OperationModes are

  • 1: Starts the RNG in the state determined by the longint Seed which is to be specified in the input parameter file.
  • 2: Continue along the random sequence from where the previous job stopped by reading in the state of the RNG from the file InFileName + ".continue". This is the normal mode of operation.
  • 3: Restarts the RNG at the sme point in the sequence the the previous job started by reading in the state of the RNG from the file InFileName + ".restart".

RanNumGen::~RanNumGen ( )
 

Class destructor.

Calls the method void WriteRanSeqParameters(string OutFileName) which writes the final state of the RNG to a file. Hence it should be explicitly called in application programs!

See also:
void WriteRanSeqParameters(string OutFileName)


Member Function Documentation

float RanNumGen::GetGaussianDeviate ( void )
 

Returns a random sample from a the 1-dimensaional Gaussian distribution with mean 0 and standard deviation 1.

This code was taken directly from Numerical Recipes in C. See http://www.nr.com/ for documention.

float RanNumGen::GetRanCosineBiased ( double alpha,
double * LikelihoodRatio )
 

The method returns a float which is the value of the biased sample.

Parameters:
alpha:   The biasing parameter.
LikelihoodRatio:   The value of the liklihood ratio of the sample that has been generated.

This is the biasing function that we used in the Reduced Model Applications.

float RanNumGen::GetRanCosineBiased ( double alpha,
double beta,
double * LikelihoodRatio )
 

This method generates a biased sample for importance sampling.

float RanNumGen::GetRanNum ( void )
 

Returns the next random number in the sequence.

This code was taken directly from Numerical Recipes in C, function ran2.\n See http://www.nr.com/ for documention.

float RanNumGen::GetRanSignBiased ( double alpha,
double * LikelihoodRatio )
 

void RanNumGen::ReadRanSeqParameters ( string InFileName )
 

Initializes the state of the RNG by reading the state parameters from a file.

void RanNumGen::ResetRanNumGen ( void )
 

Resets the RNG to the state it was in at the beginning of the job or that was saved by a call to RanNumGen::SaveCurrentState.

void RanNumGen::SaveCurrentState ( void )
 

Saves the current state of the random number generator.

Should be used in conjunction with RanNumGen::ResetRanNumGen

void RanNumGen::WriteRanSeqParameters ( string OutFileName )
 

Writes the current state of the RNG to a file.

See also:
~RanNumGen()


Member Data Documentation

const double RanNumGen::AM = 1.0/2147483563 [static, private]
 

string RanNumGen::ContinuationFileName [private]
 

The name of the file to which the current state of the RNG is written.

const double RanNumGen::EPS = 1.2e-7 [static, private]
 

const long RanNumGen::IA1 = 40014 [static, private]
 

const long RanNumGen::IA2 = 40692 [static, private]
 

const long RanNumGen::IM1 = 2147483563 [static, private]
 

const long RanNumGen::IM2 = 2147483399 [static, private]
 

const long RanNumGen::IMM1 = IM1 - 1 [static, private]
 

const long RanNumGen::IQ1 = 53668 [static, private]
 

const long RanNumGen::IQ2 = 52774 [static, private]
 

const long RanNumGen::IR1 = 12211 [static, private]
 

const long RanNumGen::IR2 = 3791 [static, private]
 

const long RanNumGen::NDIV = (1+IMM1/NTAB) [static, private]
 

const int RanNumGen::NTAB = 32 [static, private]
 

const double RanNumGen::RNMX = 1.0-EPS [static, private]
 

string RanNumGen::RestartFileName [private]
 

The name of the file to which the state of the RNG at the start of the current job is written.

long RanNumGen::idum [private]
 

long RanNumGen::idum2 [private]
 

long RanNumGen::idum2Start [private]
 

long RanNumGen::idumStart [private]
 

long RanNumGen::iv[NTAB] [private]
 

long RanNumGen::ivStart[NTAB] [private]
 

long RanNumGen::iy [private]
 

long RanNumGen::iyStart [private]
 


The documentation for this class was generated from the following files:
Generated at Mon Jun 9 20:08:11 2003 for OCS by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000