Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/classcasa_1_1RNG.html
Дата изменения: Unknown Дата индексирования: Mon Feb 14 19:48:52 2011 Кодировка: Поисковые слова: moon |
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. | |
virtual void | reset ()=0 |
Resets the random number generator. | |
virtual uInt | asuInt ()=0 |
Return the 32-random bits as an unsigned integer. | |
Float | asFloat () |
Return random bits converted to either a Float or a Double. | |
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 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;
Random numbers are used everywhere, particularly in simulations.
Definition at line 121 of file Random.h.
virtual casa::RNG::~RNG | ( | ) | [virtual] |
A virtual destructor is needed to ensure that the destructor of derived classes gets used.
Double casa::RNG::asDouble | ( | ) |
Float casa::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 casa::RNG::asuInt | ( | ) | [pure virtual] |
Return the 32-random bits as an unsigned integer.
Implemented in casa::ACG, and casa::MLCG.
virtual void casa::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 casa::ACG, and casa::MLCG.