Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
vnl_random Class Reference

A superior random number generator. More...

#include <vnl_random.h>

Public Member Functions

 vnl_random ()
 Default constructor. More...
 
 ~vnl_random ()
 Destructor. More...
 
 vnl_random (unsigned long seed)
 Construct with seed. More...
 
 vnl_random (unsigned long seed[vnl_random_array_size])
 Construct with seed. More...
 
 vnl_random (const vnl_random &)
 Copy constructor. More...
 
vnl_randomoperator= (const vnl_random &)
 Copy operator. More...
 
void reseed ()
 Starts a new non-deterministic sequence from an already declared generator. More...
 
void reseed (unsigned long)
 Starts a new deterministic sequence from an already declared generator using the provided seed. More...
 
void reseed (const unsigned long[vnl_random_array_size])
 Starts a new deterministic sequence from an already declared generator using the provided seed. More...
 
void restart ()
 This restarts the sequence of random numbers. More...
 
unsigned long lrand32 ()
 Generates a random unsigned 32-bit number. More...
 
int lrand32 (int a, int b)
 Generates a random unsigned long in [a,b]. More...
 
int lrand32 (int b)
 Generates a random unsigned long in [0,b]. More...
 
int lrand32 (int a, int b, int &)
 Generates a random unsigned long in [a,b]. More...
 
double drand32 (double a, double b)
 Generates a random double in the range a <= x <= b with 32 bit randomness. More...
 
unsigned long operator() (unsigned n)
 Generates a random unsigned integer in [0,n). More...
 
double drand32 (double b)
 Generates a random double in the range 0 <= x <= b with 32 bit randomness. More...
 
double drand32 ()
 Generates a random double in the range 0 <= x <= 1 with 32 bit randomness. More...
 
double drand64 (double a, double b)
 Generates a random double in the range a <= x <= b with 64 bit randomness. More...
 
double drand64 (double b)
 Generates a random double in the range 0 <= x <= b with 64 bit randomness. More...
 
double drand64 ()
 Generates a random double in the range 0 <= x <= 1 with 64 bit randomness. More...
 
double normal ()
 Random value from a unit normal distribution about zero. More...
 
double normal64 ()
 Random value from a unit normal distribution about zero. More...
 

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
 

Detailed Description

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 25 of file vnl_random.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
linear_congruential_multiplier 
mz_previous1 

Definition at line 27 of file vnl_random.h.

Constructor & Destructor Documentation

◆ vnl_random() [1/4]

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 52 of file vnl_random.cxx.

◆ ~vnl_random()

vnl_random::~vnl_random ( )

Destructor.

Definition at line 57 of file vnl_random.cxx.

◆ vnl_random() [2/4]

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 16 of file vnl_random.cxx.

◆ vnl_random() [3/4]

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 21 of file vnl_random.cxx.

◆ vnl_random() [4/4]

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 25 of file vnl_random.cxx.

Member Function Documentation

◆ drand32() [1/3]

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 207 of file vnl_random.cxx.

◆ drand32() [2/3]

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 114 of file vnl_random.h.

◆ drand32() [3/3]

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 118 of file vnl_random.h.

◆ drand64() [1/3]

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 213 of file vnl_random.cxx.

◆ drand64() [2/3]

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 126 of file vnl_random.h.

◆ drand64() [3/3]

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 130 of file vnl_random.h.

◆ linear_congruential_lrand32()

unsigned long vnl_random::linear_congruential_lrand32 ( )
private

Definition at line 10 of file vnl_random.cxx.

◆ lrand32() [1/4]

unsigned long vnl_random::lrand32 ( )

Generates a random unsigned 32-bit number.

Definition at line 164 of file vnl_random.cxx.

◆ lrand32() [2/4]

int vnl_random::lrand32 ( int  a,
int  b 
)

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

Definition at line 175 of file vnl_random.cxx.

◆ lrand32() [3/4]

int vnl_random::lrand32 ( int  b)
inline

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

Definition at line 98 of file vnl_random.h.

◆ lrand32() [4/4]

int vnl_random::lrand32 ( int  a,
int  b,
int &  count 
)

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

Definition at line 190 of file vnl_random.cxx.

◆ normal()

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 110 of file vnl_random.cxx.

◆ normal64()

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 140 of file vnl_random.cxx.

◆ operator()()

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 std::random_shuffle()

Definition at line 110 of file vnl_random.h.

◆ operator=()

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 38 of file vnl_random.cxx.

◆ reseed() [1/3]

void vnl_random::reseed ( )

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

Definition at line 66 of file vnl_random.cxx.

◆ reseed() [2/3]

void vnl_random::reseed ( unsigned long  seed)

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

Definition at line 71 of file vnl_random.cxx.

◆ reseed() [3/3]

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

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

Definition at line 88 of file vnl_random.cxx.

◆ restart()

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 100 of file vnl_random.cxx.

Member Data Documentation

◆ linear_congruential_previous

unsigned long vnl_random::linear_congruential_previous
private

Definition at line 28 of file vnl_random.h.

◆ mz_array

unsigned long vnl_random::mz_array[vnl_random_array_size]
private

Definition at line 30 of file vnl_random.h.

◆ mz_array_position

unsigned int vnl_random::mz_array_position
private

Definition at line 31 of file vnl_random.h.

◆ mz_borrow

int vnl_random::mz_borrow
private

Definition at line 32 of file vnl_random.h.

◆ mz_previous_normal

double vnl_random::mz_previous_normal
private

Definition at line 35 of file vnl_random.h.

◆ mz_previous_normal_flag

int vnl_random::mz_previous_normal_flag
private

Definition at line 36 of file vnl_random.h.

◆ mz_seed_array

unsigned long vnl_random::mz_seed_array[vnl_random_array_size]
private

Definition at line 29 of file vnl_random.h.


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