code::Random Class Reference

List of all members.

Detailed Description

A Random number generator that can generate both uniformly and normally distributed random numbers.

Sources:
Linear Congruential Method by D. Lehmer
Rules for above by D.E. Knuth
C++ implementation of LCM by R. Sedgewick
Dec 1995

Instantiate a new Random process by invoking the declaration:

     Random new_process(int seed);
     
and then, your sequence of random numbers may be obtained by sequentially calling
      new_process.x_int() to get random integers
   or new_process.x_dbl() to get a random double value in [0,1)
   or new_process.x_gss(sigma) to get a normally distri. double in (-inf,+inf)

e.g:  Random x(2345678);
      cout << x.x_int();
      

The Gaussian generator is not efficient -- it uses two random numbers to generate one normally-distributed one. Two such distributed values are actually available.

You can get a random seed using Random :: getSeed() This function uses the current time, process id, etc. to try to come up with a different number each time.

Author:
Lakshman
Version:
Id
code_Random.h,v 1.4 2009/06/02 20:17:40 lakshman Exp


Public Member Functions

 Random (int seed)
 Create a new random process.
int x_int ()
 Get the next random variable as integer uniformly distributed in the range [0,10^8).
double x_dbl ()
 Get the next random variable as a double uniformly distributed in the range [0,1).
double x_gss (double sigma=1.0, double mean=0.0)
 Get the next random variable normally distributed with the requested mean and passed in standard deviation.

Static Public Member Functions

static int getSeed ()
 To get a constantly changing seed to pass into the constructor if needed.


Constructor & Destructor Documentation

code::Random::Random ( int  seed  )  [inline]

Create a new random process.


Member Function Documentation

static int code::Random::getSeed (  )  [static]

To get a constantly changing seed to pass into the constructor if needed.

double code::Random::x_dbl (  ) 

Get the next random variable as a double uniformly distributed in the range [0,1).

double code::Random::x_gss ( double  sigma = 1.0,
double  mean = 0.0 
)

Get the next random variable normally distributed with the requested mean and passed in standard deviation.

int code::Random::x_int (  ) 

Get the next random variable as integer uniformly distributed in the range [0,10^8).


Generated on Fri May 4 13:40:13 2012 for WDSS-IIw2 by  doxygen 1.4.7