casa
5.7.016

Base class for random number generators. More...
#include <Random.h>
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 32random bits as an unsigned integer. More...  
Float  asFloat () 
Return random bits converted to either a Float or a Double. More...  
Double  asDouble () 
Base class for random number generators.
Public interface
RNG stands for "Random Number Generator"
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.
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 32bit 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 32bit 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;
Random numbers are used everywhere, particularly in simulations.

virtual 
A virtual destructor is needed to ensure that the destructor of derived classes gets used.
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

pure virtual 
Return the 32random bits as an unsigned integer.
Implemented in casacore::MLCG, and casacore::ACG.

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.