RandomLib  1.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Code organization
Back to Getting started. Forward to The seed. Up to Contents.

Random manipulates the data arrays, the seed and the state. These are managed by the following classes, which are all defined in the RandomLib namespace:

For most purposes, users should ignore the existence of RandomSeed, RandomEngine, RandomGenerator, and RandomCanonical and access all the capabilities of these classes via thru the class Random which inherits all the needed functionality of its base classes. This documentation reflects this recommendation. (In restricted applications, a user might wish to interface to the library via the lower-level RandomGenerator class as a source of random words.)

Unfortunately the relation between this classes is sufficiently complicated to defeat doxygen's indexing capabilities; if you need to look up the definition of one of Random's member functions, you can refer to the brief index in Function index.

Finally, distributions such as the normal and exponential distribution are provided by the classes NormalDistribution and ExponentialDistribution. They access the random data by being passed a Random object as an argument to operator().

Several errors in using RandomLib are caught at compile time. Runtime errors are signaled by throwing RandomErr exceptions with a explanatory message.

RandomLib includes facilities for sampling from the uniform, exponential, and normal distributions using MPFR (version 3.0 and later). These are a header-only interface (the header names all being with "MPFR") which use MPFR's random number generator and may be used apart from the rest of RandomLib. MPFRExample.cpp illustrates their use. See MPFR interface for more information.

These routines have been developed and tested with g++ version 4.x under Linux 2.6.x on 32-bit and 64-bit Intel and 64-bit AMD CPUs, MS Visual Studio 2005 and 2008, under Windows. Earlier versions of this library were tested with g++ under Darwin on a PowerPC and under Solaris on 64-bit SPARC platforms. Porting to other platforms with a standard C++ compiler and template library should be straightforward provided that the radix for integer and real types is 2.

A note about portability. For the most part, the code uses standard C++. System dependencies creep into the computation of SeedVector and SeedWord (e.g., to access the PID and the high-precision clock). In addition, it's assumed that unsigned integers can be cast into signed integers preserving the bit pattern (assuming a twos-complement convention for signed numbers). Visual Studio 2005, 2008, 2010 compiling for a 32-bit machines have a bug in their standard template library implementations which prevent you from creating vectors of SFMT19937 generators if they are compiled with SSE2 instructions (via HAVE_SSE2); this prevents you from using, for example, a std::vector to hold such objects. To circumvent this bug you will need to create your own containers which call new and delete explicitly. (RandomLib includes new and new[] operators for SFMT19937 which return correctly aligned blocks of memory.) See RandomThread.cpp for an example of a simple fixed-size container.

Back to Getting started. Forward to The seed. Up to Contents.