casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
casacore::RNG Class Referenceabstract

Base class for random number generators. More...

#include <Random.h>

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

Public Member Functions

virtual ~RNG ()
 A virtual destructor is needed to ensure that the destructor of derived classes gets used. More...
 
virtual void reset ()=0
 Resets the random number generator. More...
 
virtual uInt asuInt ()=0
 Return the 32-random bits as an unsigned integer. More...
 
Float asFloat ()
 Return random bits converted to either a Float or a Double. More...
 
Double asDouble ()
 

Detailed Description

Base class for random number generators.

Intended use:

Public interface

Review Status

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

Prerequisite

Etymology

RNG stands for "Random Number Generator"

Synopsis

General Structure of the Classes

The two base classes RNG and Random are used together to generate a variety of random number distributions. A distinction must be made between random number generators, implemented by class derived from RNG, and random number distributions. A random number generator produces a series of randomly ordered bits. These bits can be used directly, or cast to another representation, such as a floating point value. A random number generator should produce a uniform distribution. A random number distribution, on the other hand, uses the randomly generated bits of a generator to produce numbers from a distribution with specific properties. Each instance of Random uses an instance of class RNG to provide the raw, uniform distribution used to produce the specific distribution. Several instances of Random classes can share the same instance of RNG, or each instance can use its own copy.

RNG

Random distributions are constructed from classes derived from RNG, the actual random number generators. The RNG class contains no data; it only serves to define the interface to random number generators. The RNG::asuInt member returns a 32-bit unsigned integer of random bits. Applications that require a number of random bits can use this directly. More often, these random bits are transformed to a uniformly distributed floating point number using either asFloat or asDouble. These functions return differing precisions and the asDouble function will use two different random 32-bit integers to get a legal double, while asFloat will use a single integer. These members are used by classes derived fro the Random base class to implement a variety of random number distributions.

Currently, the following subclasses are provided:


Warning: This class assumes that IEEE floating point representation is used for the floating point numbers and that the integer and unsigned integer type is exactly 32 bits long;

Example

Motivation

Random numbers are used everywhere, particularly in simulations.

Thrown Exceptions

To Do

Definition at line 122 of file Random.h.

Constructor & Destructor Documentation

virtual casacore::RNG::~RNG ( )
virtual

A virtual destructor is needed to ensure that the destructor of derived classes gets used.

Member Function Documentation

Double casacore::RNG::asDouble ( )
Float casacore::RNG::asFloat ( )

Return random bits converted to either a Float or a Double.

The returned value x is in the range 1.0 > x >= 0.0

virtual uInt casacore::RNG::asuInt ( )
pure virtual

Return the 32-random bits as an unsigned integer.

Implemented in casacore::MLCG, and casacore::ACG.

virtual void casacore::RNG::reset ( )
pure 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.

Implemented in casacore::MLCG, and casacore::ACG.


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