casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
casacore::ACG Class Reference

Additive number generator. More...

#include <Random.h>

Inheritance diagram for casacore::ACG:
casacore::RNG

Public Member Functions

 ACG (uInt seed=0, Int size=55)
 The constructor allows you to specify seeds. More...
 
virtual ~ACG ()
 The destructor cleans up memory allocated by this class. More...
 
virtual void reset ()
 Resets the random number generator. More...
 
virtual uInt asuInt ()
 Return the 32-random bits as an unsigned integer. More...
 
- Public Member Functions inherited from casacore::RNG
virtual ~RNG ()
 A virtual destructor is needed to ensure that the destructor of derived classes gets used. More...
 
Float asFloat ()
 Return random bits converted to either a Float or a Double. More...
 
Double asDouble ()
 

Private Attributes

uInt itsInitSeed
 
Int itsInitTblEntry
 
uIntitsStatePtr
 
uIntitsAuxStatePtr
 
Short itsStateSize
 
Short itsAuxSize
 
uInt lcgRecurr
 
Short itsJ
 
Short itsK
 

Detailed Description

Additive number generator.

Intended use:

Public interface

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Prerequisite

Etymology

ACG stands for "Additive Congruential Generator"

Synopsis

This class implements the additive number generator as presented in Volume II of The Art of Computer Programming by Knuth. I have coded the algorithm and have added the extensions by Andres Nowatzyk of CMU to randomize the result of algorithm M a bit by using an LCG & a spatial permutation table.

The version presented uses the same constants for the LCG that Andres uses (chosen by trial & error). The spatial permutation table is the same size (it is based on word size). This is for 32-bit words.

The auxillary table used by the LCG table varies in size, and is chosen to be the the smallest power of two which is larger than twice the size of the state table.

Class ACG is a variant of a Linear Congruential Generator (Algorithm M) described in Knuth, "Art of Computer Programming, Vol III". This result is permuted with a Fibonacci Additive Congruential Generator to get good independence between samples. This is a very high quality random number generator, although it requires a fair amount of memory for each instance of the generator.

The constructor takes two parameters: the seed and the size. The seed can be any number. The performance of the generator depends on having a distribution of bits through the seed. If you choose a number in the range of 0 to 31, a seed with more bits is chosen. Other values are deterministically modified to give a better distribution of bits. This provides a good random number generator while still allowing a sequence to be repeated given the same initial seed.

The size parameter determines the size of two tables used in the generator. The first table is used in the Additive Generator; see the algorithm in Knuth for more information. In general, this table contains size integers. The default value, used in the algorithm in Knuth, gives a table of 55 integers (220 bytes). The table size affects the period of the generators; smaller values give shorter periods and larger tables give longer periods. The smallest table size is 7 integers, and the longest is 98. The size parameter also determines the size of the table used for the Linear Congruential Generator. This value is chosen implicitly based on the size of the Additive Congruential Generator table. It is two powers of two larger than the power of two that is larger than size. For example, if size is 7, the ACG table contains 7 integers and the LCG table contains 128 integers. Thus, the default size (55) requires 55 + 256 integers, or 1244 bytes. The largest table requires 2440 bytes and the smallest table requires 100 bytes. Applications that require a large number of generators or applications that are not so fussy about the quality of the generator may elect to use the MLCG generator.


Warning: This class assumes that the integer and unsigned integer type is exactly 32 bits long;

Example

Thrown Exceptions

To Do

Definition at line 224 of file Random.h.

Constructor & Destructor Documentation

casacore::ACG::ACG ( uInt  seed = 0,
Int  size = 55 
)
explicit

The constructor allows you to specify seeds.

The seed should be a big random number and size must be between 7 and 98. See the synopsis for more details.

virtual casacore::ACG::~ACG ( )
virtual

The destructor cleans up memory allocated by this class.

Member Function Documentation

virtual uInt casacore::ACG::asuInt ( )
virtual

Return the 32-random bits as an unsigned integer.

Implements casacore::RNG.

virtual void casacore::ACG::reset ( )
virtual

Resets the random number generator.

After calling this function the random numbers generated will be the same as if the object had just been constructed.

Implements casacore::RNG.

Member Data Documentation

Short casacore::ACG::itsAuxSize
private

Definition at line 250 of file Random.h.

uInt* casacore::ACG::itsAuxStatePtr
private

Definition at line 248 of file Random.h.

uInt casacore::ACG::itsInitSeed
private

Definition at line 244 of file Random.h.

Int casacore::ACG::itsInitTblEntry
private

Definition at line 245 of file Random.h.

Short casacore::ACG::itsJ
private

Definition at line 252 of file Random.h.

Short casacore::ACG::itsK
private

Definition at line 253 of file Random.h.

uInt* casacore::ACG::itsStatePtr
private

Definition at line 247 of file Random.h.

Short casacore::ACG::itsStateSize
private

Definition at line 249 of file Random.h.

uInt casacore::ACG::lcgRecurr
private

Definition at line 251 of file Random.h.


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