DIPlib Documentation - ©1995-2013 Quantitative Imaging Group, Delft University of Technology.

# RandomVariable

Random number generator

## SYNOPSIS

`include "dip_noise.h"`

dip_Error dip_RandomVariable ( random, value )

## FUNCTION

Generates a random number between zero and one. The `dip_Random` structure must be initialized with the function `RandomSeed`. If the supplied `dip_Random` structure is not initialized, `RandomVariable` will initialize the `dip_Random` structure with the default seed. To guarantee the (psuedo) randomness between variables obtained with subsequent calls to `RandomVariable` (or to functions that use this function to obtain a random variable), a pointer to the same `dip_Random` structure has to supplied when calling `RandomVariable`.

The random number generator returns random numbers as 32-bit integers, which are normalised to to [0,1] range. If higher precision numbers are required, you can set `random.highprecision` to `DIP_TRUE`. This causes two random 32-bit values to be used for each floating point output value, doubling the precision of the output. There is no need to re-initialise the `random` structure after changing this setting.

This function is based on LGPL code by Geoff Kuenning (mtwist-0.8) implementing the Mersenne Twister pseudo-random number generator.

## ARGUMENTS

Data type | Name | Description
`dip_Random *` | `random` | Pointer to a random value structure
`dip_float *` | `value` | Random value

## EXAMPLE

Obtain a random number as follows:

       dip_Random random;
       dip_float val;

       DIPXJ( dip_RandomSeed( &random, 0 ));
       DIPXJ( dip_RandomVariable( &random, &val ));

## LITERATURE

Makoto Matsumoto and Takuji Nishimura, Mersenne twister: a 623-dimensionally equidistributed uniform pseudo-random number generator, ACM Transactions on Modeling and Computer Simulation 8(1):3-30, 1998.

## SEE ALSO

`RandomSeed`, `RandomSeedVector`, `UniformRandomVariable`, `GaussianRandomVariable`, `PoissonRandomVariable`, `BinaryRandomVariable`

Code source: mtwist-0.8 or mtwist-0.8