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_random & | operator= (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 |
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.
|
private |
| Enumerator | |
|---|---|
| linear_congruential_multiplier | |
| mz_previous1 | |
Definition at line 27 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 52 of file vnl_random.cxx.
| vnl_random::~vnl_random | ( | ) |
Destructor.
Definition at line 57 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 16 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 21 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 25 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 207 of file vnl_random.cxx.
|
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.
|
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.
| 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.
|
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.
|
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.
|
private |
Definition at line 10 of file vnl_random.cxx.
| unsigned long vnl_random::lrand32 | ( | ) |
Generates a random unsigned 32-bit number.
Definition at line 164 of file vnl_random.cxx.
| 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.
|
inline |
Generates a random unsigned long in [0,b].
Definition at line 98 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 190 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 110 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 140 of file vnl_random.cxx.
|
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.
| 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.
| void vnl_random::reseed | ( | ) |
Starts a new non-deterministic sequence from an already declared generator.
Definition at line 66 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 71 of file vnl_random.cxx.
| 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.
| 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.
|
private |
Definition at line 28 of file vnl_random.h.
|
private |
Definition at line 30 of file vnl_random.h.
|
private |
Definition at line 31 of file vnl_random.h.
|
private |
Definition at line 32 of file vnl_random.h.
|
private |
Definition at line 35 of file vnl_random.h.
|
private |
Definition at line 36 of file vnl_random.h.
|
private |
Definition at line 29 of file vnl_random.h.
1.8.15