class Random

Encapsule the functions from the book "Numercial Recipes in C" 'Minimal' random number generator of Park and Miller with Bays-Durham shuffle and added safeguards.

Public Methods

[more]void SeedIt(int seed)
Seed the random number generator.
[more]double Rand()
Request a double precision value between 0 and 1
[more]int iRand()
Request an integer value from 0 to integer max-1.
[more]double RandRange(double* input)
This function encapsulates the code to initialize a variable with a random value uniformly distributed within a range.
[more]double Gauss()
This routine is from "Numerical Recipes in C".
[more]double GaussNum(double* input)
This function encapsulates the code to initialize a variable with a gaussian random distribution.
[more]float GaussNum( float* intpu )
Overloaded version of double GaussNum.
[more]double* GaussArray(double* array, int num, double stdev)
Given an array of numbers and a standard deviation, applies gaussian function to them.


Documentation

Encapsule the functions from the book "Numercial Recipes in C" 'Minimal' random number generator of Park and Miller with Bays-Durham shuffle and added safeguards. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of the endpoint values). Call with IDUM a negative integer to initialize; thereafter, do not alter idum between successive deviates in a sequence. RNMAX should approximate the largest double value that is less than 1.0"
ovoid SeedIt(int seed)
Seed the random number generator. Note that if a negative number is not sent for the seed value, it will default to one.
Parameters:
seed - The value to use for idum; must be negative.

odouble Rand()
Request a double precision value between 0 and 1
Returns:
Value between zero and one (exclusive)

oint iRand()
Request an integer value from 0 to integer max-1. The user should use the modulus operator to limit the number to the appropriate range. ex. Rand()%20 for 0 to 19
Returns:
Value between 0 and integer max-1

odouble RandRange(double* input)
This function encapsulates the code to initialize a variable with a random value uniformly distributed within a range. input is a two element array that is the start and end of the range. It is assumed that input [0] < input [1]: this error check should be done in the input.
Parameters:
- input Two-element array containing the minimum value and maximum value
Returns:
A value that exists between the minimum and maximum value

odouble Gauss()
This routine is from "Numerical Recipes in C". Returns a normally distributed deviate with zero mean and unit variance, using Rand as the source of uniform deviates. Each call actually creates two deviates: the extra is saved for the next call.
Returns:
The value selected as the next random number

odouble GaussNum(double* input)
This function encapsulates the code to initialize a variable with a gaussian random distribution. Most variables that can have a gaussian applied have a common format: mean and standard deviation in a two-element array. (If stdev is zero, result is just the mean.)
Parameters:
- input Two-element array containing the mean and standard deviation
Returns:
the resulting value (mean + Guass()*stddev)

ofloat GaussNum( float* intpu )
Overloaded version of double GaussNum. This function merely typecasts the float parameters into double containers so that it can call the original GaussNum function. The result is then typecast back to a float and returned.

Parameters:
- input Two-element float array contain the mean and standard deviation
Returns:
The resulting value (mean + Guass()*stddev)

odouble* GaussArray(double* array, int num, double stdev)
Given an array of numbers and a standard deviation, applies gaussian function to them. If the standard deviation is zero, simply returns a pointer to a the original array; otherwise, allocates a new array and returns a pointer to it. (This is to save memory.)
Parameters:
array - The original array of numbers
num - Number of elements in the array
stdev - The standard deviation that will be applied to each element of the array
Returns:
Pointer to the array with the final values


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.