Public Member Functions | |
RanQD1 (long seed) | |
void | setSeed (long seed) |
long | nextLong () |
double | nextDouble () |
int | nextInt (int min, int max) |
This class implements the (repeatable) "quick and dirty" portable pseudo-random generator with modulus 232 in W. H. Press et al, "Numerical Recipes in C: The Art of Scientific Computing", Cambridge University Press, 2nd Ed., 1992, with values recommended by Knuth. It is the fastest generator recommended in the above tome.
The original relies on the fact that in C on a 32-bit machine, multiplying two unsigned long ints returns the lower 32 bits of the 64 bit product. Since we are using Java (no unsigned ints) and a 64-bit architecture, we mimic this using 64 bit longs with bit-masking instead.
Definition at line 26 of file RanQD1.java.
RanQD1::RanQD1 | ( | long | seed | ) | [inline] |
Create a new pseudo-random generator.
seed | the seed |
Definition at line 39 of file RanQD1.java.
double RanQD1::nextDouble | ( | ) | [inline] |
Get the next double.
Definition at line 64 of file RanQD1.java.
int RanQD1::nextInt | ( | int | min, | |
int | max | |||
) | [inline] |
Get an integer with equal probability from [min, max] inclusive.
Definition at line 71 of file RanQD1.java.
long RanQD1::nextLong | ( | ) | [inline] |
Get the next long.
Definition at line 56 of file RanQD1.java.
void RanQD1::setSeed | ( | long | seed | ) | [inline] |
Reset the seed (quicker than creating a new instance).
seed | the seed |
Definition at line 48 of file RanQD1.java.