vnl_random Class Reference

A superior random number generator. More...

`#include <vnl_random.h>`

## Public Member Functions | |

vnl_random () | |

Default constructor. | |

~vnl_random () | |

Destructor. | |

vnl_random (unsigned long seed) | |

Construct with seed. | |

vnl_random (unsigned long seed[vnl_random_array_size]) | |

Construct with seed. | |

vnl_random (const vnl_random &) | |

Copy constructor. | |

vnl_random & | operator= (const vnl_random &) |

Copy operator. | |

void | reseed () |

Starts a new non-deterministic sequence from an already declared generator. | |

void | reseed (unsigned long) |

Starts a new deterministic sequence from an already declared generator using the provided seed. | |

void | reseed (unsigned long[vnl_random_array_size]) |

Starts a new deterministic sequence from an already declared generator using the provided seed. | |

void | restart () |

This restarts the sequence of random numbers. | |

unsigned long | lrand32 () |

Generates a random unsigned 32-bit number. | |

int | lrand32 (int a, int b) |

Generates a random unsigned long in [a,b]. | |

int | lrand32 (int b) |

Generates a random unsigned long in [0,b]. | |

int | lrand32 (int a, int b, int &) |

Generates a random unsigned long in [a,b]. | |

double | drand32 (double a, double b) |

Generates a random double in the range a <= x <= b with 32 bit randomness. | |

unsigned long | operator() (unsigned n) |

Generates a random unsigned integer in [0,n). | |

double | drand32 (double b) |

Generates a random double in the range 0 <= x <= b with 32 bit randomness. | |

double | drand32 () |

Generates a random double in the range 0 <= x <= 1 with 32 bit randomness. | |

double | drand64 (double a, double b) |

Generates a random double in the range a <= x <= b with 64 bit randomness. | |

double | drand64 (double b) |

Generates a random double in the range 0 <= x <= b with 64 bit randomness. | |

double | drand64 () |

Generates a random double in the range 0 <= x <= 1 with 64 bit randomness. | |

double | normal () |

Random value from a unit normal distribution about zero. | |

double | normal64 () |

Random value from a unit normal distribution about zero. | |

## Private Types | |

enum | { linear_congruential_multiplier = 1664525, mz_previous1 = 24 } |

## Private Member Functions | |

unsigned long | linear_congruential_lrand32 () |

## Private Attributes | |

unsigned long | linear_congruential_previous |

unsigned long | mz_seed_array [vnl_random_array_size] |

unsigned long | mz_array [vnl_random_array_size] |

unsigned int | mz_array_position |

int | mz_borrow |

double | mz_previous_normal |

int | mz_previous_normal_flag |

A superior random number generator.

Implements a new random number generator that recently appeared in the literature. It generates 32 bit numbers with a higher degree of randomness than previous generators and has a cycle of 10^354 i.e. so huge that in practice it never cycles. For the mathematics behind it see: "A New Class of Random Number Generators" G. Marsaglia and A. Zaman, Annals of Applied Probability 1991, Vol. 1, No. 3, 462.

Definition at line 23 of file vnl_random.h.

anonymous enum` [private]` |

Definition at line 25 of file vnl_random.h.

vnl_random::vnl_random | ( | ) |

Default constructor.

Initializes the random number generator non-deterministically. i.e. it will generate a different series of random numbers each time the program is run.

Definition at line 55 of file vnl_random.cxx.

vnl_random::~vnl_random | ( | ) |

Destructor.

Definition at line 60 of file vnl_random.cxx.

vnl_random::vnl_random | ( | unsigned long | seed | ) |

Construct with seed.

Initializes the random number generator deterministically using a single ulong as the 'seed'. A linear congruential generator is used to generate the 37 ulongs needed as the real seed. The same seed will produce the same series of random numbers.

9667566 is a good seed.

Definition at line 19 of file vnl_random.cxx.

vnl_random::vnl_random | ( | unsigned long | seed[vnl_random_array_size] | ) |

Construct with seed.

Initializes the random number generator deterministically using 37 ulongs as the 'seed'. The same seed will produce the same series of random numbers.

Definition at line 24 of file vnl_random.cxx.

vnl_random::vnl_random | ( | const vnl_random & | r | ) |

Copy constructor.

Initializes/sets the random number generator to exactly the same state as the argument, i.e. both will generate exactly the same series of random numbers from then on.

Definition at line 28 of file vnl_random.cxx.

double vnl_random::drand32 | ( | double | a, |

double | b |
||

) |

Generates a random double in the range a <= x <= b with 32 bit randomness.

drand32(1,0) is random down to about the 10th decimal place.

Definition at line 210 of file vnl_random.cxx.

double vnl_random::drand32 | ( | double | b | ) | ` [inline]` |

Generates a random double in the range 0 <= x <= b with 32 bit randomness.

drand32(1.0) is random down to about the 10th decimal place.

Definition at line 112 of file vnl_random.h.

double vnl_random::drand32 | ( | ) | ` [inline]` |

Generates a random double in the range 0 <= x <= 1 with 32 bit randomness.

drand32() is random down to about the 10th decimal place.

Definition at line 116 of file vnl_random.h.

double vnl_random::drand64 | ( | double | a, |

double | b |
||

) |

Generates a random double in the range a <= x <= b with 64 bit randomness.

Completely random down to the accuracy of an IEEE double.

Definition at line 216 of file vnl_random.cxx.

double vnl_random::drand64 | ( | double | b | ) | ` [inline]` |

Generates a random double in the range 0 <= x <= b with 64 bit randomness.

Completely random down to the accuracy of an IEEE double.

Definition at line 124 of file vnl_random.h.

double vnl_random::drand64 | ( | ) | ` [inline]` |

Generates a random double in the range 0 <= x <= 1 with 64 bit randomness.

Completely random down to the accuracy of an IEEE double.

Definition at line 128 of file vnl_random.h.

unsigned long vnl_random::linear_congruential_lrand32 | ( | ) | ` [private]` |

Definition at line 13 of file vnl_random.cxx.

unsigned long vnl_random::lrand32 | ( | ) |

Generates a random unsigned 32-bit number.

Definition at line 167 of file vnl_random.cxx.

int vnl_random::lrand32 | ( | int | a, |

int | b |
||

) |

Generates a random unsigned long in [a,b].

Definition at line 178 of file vnl_random.cxx.

int vnl_random::lrand32 | ( | int | b | ) | ` [inline]` |

Generates a random unsigned long in [0,b].

Definition at line 96 of file vnl_random.h.

int vnl_random::lrand32 | ( | int | a, |

int | b, |
||

int & | count |
||

) |

Generates a random unsigned long in [a,b].

Definition at line 193 of file vnl_random.cxx.

double vnl_random::normal | ( | ) |

Random value from a unit normal distribution about zero.

Uses a drand32() as its underlying generator. Because the function uses a probability transform, the randomness (and quantisation) is non-linearly dependent on the value. The further the sample is from zero, the lower the number of bits on which it is random.

Definition at line 113 of file vnl_random.cxx.

double vnl_random::normal64 | ( | ) |

Random value from a unit normal distribution about zero.

Uses a drand64() as its underlying generator. Because the function uses a probability transform, the randomness (and quantisation) is non-linearly dependent on the value. The further the sample is from zero, the lower the number of bits on which it is random.

Definition at line 143 of file vnl_random.cxx.

unsigned long vnl_random::operator() | ( | unsigned | n | ) | ` [inline]` |

Generates a random unsigned integer in [0,n).

This function allows the random number generator to be used as a functor, e.g. with vcl_random_shuffle()

Definition at line 108 of file vnl_random.h.

vnl_random & vnl_random::operator= | ( | const vnl_random & | r | ) |

Copy operator.

Initializes/sets the random number generator to exactly the same state as the argument, i.e. both will generate exactly the same series of random numbers from then on.

Definition at line 41 of file vnl_random.cxx.

void vnl_random::reseed | ( | ) |

Starts a new non-deterministic sequence from an already declared generator.

Definition at line 69 of file vnl_random.cxx.

void vnl_random::reseed | ( | unsigned long | seed | ) |

Starts a new deterministic sequence from an already declared generator using the provided seed.

Definition at line 74 of file vnl_random.cxx.

void vnl_random::reseed | ( | unsigned long | seed[vnl_random_array_size] | ) |

Starts a new deterministic sequence from an already declared generator using the provided seed.

Definition at line 91 of file vnl_random.cxx.

void vnl_random::restart | ( | ) |

This restarts the sequence of random numbers.

Restarts so that it repeats from the point at which you declared the generator, last initialized it, or last called a 'reseed'.

Definition at line 103 of file vnl_random.cxx.

unsigned long vnl_random::linear_congruential_previous` [private]` |

Definition at line 26 of file vnl_random.h.

unsigned long vnl_random::mz_array[vnl_random_array_size]` [private]` |

Definition at line 28 of file vnl_random.h.

unsigned int vnl_random::mz_array_position` [private]` |

Definition at line 29 of file vnl_random.h.

int vnl_random::mz_borrow` [private]` |

Definition at line 30 of file vnl_random.h.

double vnl_random::mz_previous_normal` [private]` |

Definition at line 33 of file vnl_random.h.

int vnl_random::mz_previous_normal_flag` [private]` |

Definition at line 34 of file vnl_random.h.

unsigned long vnl_random::mz_seed_array[vnl_random_array_size]` [private]` |

Definition at line 27 of file vnl_random.h.

The documentation for this class was generated from the following files:

- core/vnl/vnl_random.h
- core/vnl/vnl_random.cxx

Generated on Wed Jul 22 2015 22:02:41 for core/vnl by 1.7.5.1