All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes
Random number generation

Classes

class  blaze::Random< Type >
 Random number generator.The Random class encapsulates the initialization of the given random number generator with a pseudo-random seed obtained by the std::time() function. Currently, the mersenne-twister mt19937 as provided by the boost library is used per default. For more information see the class description of the boost library: More...
 
class  blaze::Rand< typename >
 Default implementation of the Rand class for integral data types.This default implementation of the Rand class creates random, integral numbers in the range $ [0..max] $, where max is the maximal value of the given data type T. More...
 

Random number functions

template<typename T >
blaze::rand ()
 Random number function. More...
 
template<typename T , typename A1 >
blaze::rand (const A1 &a1)
 Random number function. More...
 
template<typename T , typename A1 , typename A2 >
blaze::rand (const A1 &a1, const A2 &a2)
 Random number function. More...
 
template<typename T , typename A1 , typename A2 , typename A3 >
blaze::rand (const A1 &a1, const A2 &a2, const A3 &a3)
 Random number function. More...
 
template<typename T , typename A1 , typename A2 , typename A3 , typename A4 >
blaze::rand (const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
 Random number function. More...
 
template<typename T , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 >
blaze::rand (const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
 Random number function. More...
 
uint32_t blaze::getSeed ()
 Returns the current seed of the random number generator. More...
 
void blaze::setSeed (uint32_t seed)
 Setting the seed of the random number generator. More...
 

Detailed Description

The random number module provides the functionality to generate pseudo-random numbers within the Blaze library. In order to create series of random numbers, the following functions are are provided:

The templated rand() function is capable of generating random numbers for built-in integer and floating point data types as well as complex values. The rand() function can be given up to five parameters that depending on the type of the random number may have different meaning. The following example demonstrates the random number generation:

using namespace blaze;
// The setSeed function sets the seed for the random number generator. This function can
// be used to set a specific seed for the random number generation, e.g. in order to
// reproduce an exact series of random numbers. If the setSeed function is not used, the
// random number generation uses a random seed.
setSeed( 12345 );
// In order to acquire the currently used seed, the getSeed() function can be used.
uint32_t seed = getSeed();
// Generating random numbers of built-in type. In case no range is provided, random numbers
// of integral type are generated in the range [0..max], where max is the largest possible
// value of the specified type and random floating point numbers are generated in the range
// [0..1). In the example, the random double precision floating point value is created in
// the range [2..4].
int i = rand<int>();
double d = rand<double>( 2.0, 4.0 );
// Generating random complex numbers. In case no range is provided, both the real and the
// imaginary part are created depending on the element type of the complex number. In case
// one range is specified, both the real and the imaginary part are created within the
// specified range. In the example, both parts are created within the range [1..4]. If two
// ranges are provided, the real part is created in the first range and the imaginary part
// is created in the second range. The last example demonstrates this by restricting the
// real part to the range [2..3] and the imaginary part to the range [1..5].
complex<float> c1 = rand< complex<float> >();
complex<float> c2 = rand< complex<float> >( 1.0F, 4.0F );
complex<float> c3 = rand< complex<float> >( 2.0F, 3.0F, 1.0F, 5.0F );

Note: In order to reproduce certain series of random numbers, the seed of the random number generator has to be set explicitly via the setSeed() function. Otherwise a random seed is used for the random number generation.

Function Documentation

uint32_t blaze::getSeed ( )
inline

Returns the current seed of the random number generator.

Returns
The current seed of the random number generator.
template<typename T >
T blaze::rand ( )
inline

Random number function.

Returns
The generated random number.

The rand() function returns a default random number depending on the given data type. In case of integral data types, the function returns a random number in the range $ [0..max] $, where max is the maximal value of the data type T. In case of floating point data types, the function returns a random number in the range $ [0..1) $. In case of complex data types, the function returns a random complex value where both the real and the imaginary part have been set according to the element type of the complex value ( $ [0..max] $ for integral elements, $ [0..1) $ for floating point elements).

template<typename T , typename A1 >
T blaze::rand ( const A1 &  a1)
inline

Random number function.

Parameters
a1First argument for the random number generation.
Returns
The generated random number.

This rand() function creates a random number based on the given argument a1.

template<typename T , typename A1 , typename A2 >
T blaze::rand ( const A1 &  a1,
const A2 &  a2 
)
inline

Random number function.

Parameters
a1First argument for the random number generation.
a2Second argument for the random number generation.
Returns
The generated random number.

This rand() function creates a random number based on the given arguments a1 and a2.

template<typename T , typename A1 , typename A2 , typename A3 >
T blaze::rand ( const A1 &  a1,
const A2 &  a2,
const A3 &  a3 
)
inline

Random number function.

Parameters
a1First argument for the random number generation.
a2Second argument for the random number generation.
a3Third argument for the random number generation.
Returns
The generated random number.

This rand() function creates a random number based on the given arguments a1, a2, and a3.

template<typename T , typename A1 , typename A2 , typename A3 , typename A4 >
T blaze::rand ( const A1 &  a1,
const A2 &  a2,
const A3 &  a3,
const A4 &  a4 
)
inline

Random number function.

Parameters
a1First argument for the random number generation.
a2Second argument for the random number generation.
a3Third argument for the random number generation.
a4Fourth argument for the random number generation.
Returns
The generated random number.

This rand() function creates a random number based on the given arguments a1, a2, a3, and a4.

template<typename T , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 >
T blaze::rand ( const A1 &  a1,
const A2 &  a2,
const A3 &  a3,
const A4 &  a4,
const A5 &  a5 
)
inline

Random number function.

Parameters
a1First argument for the random number generation.
a2Second argument for the random number generation.
a3Third argument for the random number generation.
a4Fourth argument for the random number generation.
a5Fifth argument for the random number generation.
Returns
The generated random number.

This rand() function creates a random number based on the given arguments a1, a2, a3, a4, and a5.

void blaze::setSeed ( uint32_t  seed)
inline

Setting the seed of the random number generator.

Parameters
seedThe new seed for the random number generator.
Returns
void

This function can be used to set the seed for the random number generation in order to create a reproducible series of random numbers.