A utility class that simplifies the generation of random numbers.
More...
#include <Random.h>
A utility class that simplifies the generation of random numbers.
OpenANN::RandomNumberGenerator::RandomNumberGenerator |
( |
) | |
|
template<class M >
void OpenANN::RandomNumberGenerator::fillNormalDistribution |
( |
M & |
matrix, |
|
|
double |
stdDev = 1.0 |
|
) |
| |
|
inline |
template<class T >
T OpenANN::RandomNumberGenerator::generate |
( |
T |
min, |
|
|
T |
range |
|
) |
| const |
|
inline |
Draw a number from a uniform distribution.
- Template Parameters
-
- Parameters
-
min | minimal value |
range | range of the interval, must be greater than 0 |
- Returns
- random number from the interval [min, range)
size_t OpenANN::RandomNumberGenerator::generateIndex |
( |
size_t |
size) | |
const |
Draw an index from a uniform distribution.
- Parameters
-
size | range of the index, must be greater than 0 |
- Returns
- random number from the interval [0, size)
template<class C >
void OpenANN::RandomNumberGenerator::generateIndices |
( |
int |
n, |
|
|
C & |
result, |
|
|
bool |
initialized = false |
|
) |
| |
|
inline |
Generate a random sequence of indices.
- Template Parameters
-
container | type of result (must support push_back()) |
- Parameters
-
n | number of indices |
result | result container, must be empty if initialized = false |
initialized | does the container already contain indices? |
int OpenANN::RandomNumberGenerator::generateInt |
( |
int |
min, |
|
|
int |
range |
|
) |
| const |
Draw an integer from a uniform distribution.
- Parameters
-
min | minimal value |
range | range of the interval, must be greater than 0 |
- Returns
- random number from the interval [min, range)
template<class T >
T OpenANN::RandomNumberGenerator::sampleNormalDistribution |
( |
) | |
const |
|
inline |
Draw a sample from a normal distribution with zero mean and variance 1.
We use the Box–Muller transform. In order to draw a random number from the distribution , you have to shift and scale the output of this function:
double mu = ...
double sigma = ...
double rn = mu + sigma*rng.sampleNormalDistribution<double>();
- Template Parameters
-
- Returns
- standard normal distributed random number
void OpenANN::RandomNumberGenerator::seed |
( |
unsigned int |
seed) | |
|
Set the seed to ensure repeatability.
Note that the seed is set globally, i.e. it might also be overwritten by another part of you program.
- Parameters
-
seed | initial parameter for random number generator |
The documentation for this class was generated from the following file: