cz.cuni.jagrlib
Class RandomJames

java.lang.Object
  extended by cz.cuni.jagrlib.RandomJames

public class RandomJames
extends java.lang.Object

Random number generator by F. James adopted by Phil Linttell, James F. Hickling & Josef Pelikan.

This random number generator originally appeared in "Toward a Universal Random Number Generator" by George Marsaglia and Arif Zaman. Florida State University Report: FSU-SCRI-87-50 (1987)

It was later modified by F. James and published in "A Review of Pseudo-random Number Generators"

Converted from FORTRAN to C by Phil Linttell, James F. Hickling Management Consultants Ltd, Aug. 14, 1989.

THIS IS THE BEST KNOWN RANDOM NUMBER GENERATOR AVAILABLE. (However, a newly discovered technique can yield a period of 10^600. But that is still in the development stage.)

It passes ALL of the tests for random number generators and has a period of 2^144, is completely portable (gives bit identical results on all machines with at least 24-bit mantissas in the floating point representation).

The algorithm is a combination of a Fibonacci sequence (with lags of 97 and 33, and operation "subtraction plus one, modulo one") and an "arithmetic sequence" (using subtraction).

On a Vax 11/780, this random number generator can produce a number in 13 microseconds.

Since:
0.24
See Also:
RandomJames.java

Field Summary
protected  double c
           
protected  double cd
           
protected  double cm
           
protected  int i97
           
protected  int j97
           
protected  double norAdd
           
protected  double norMul
           
 boolean ok
          Success flag.
protected  int[] perm
           
protected  int permPtr
           
protected  int permSize
           
protected  double prepMean
           
protected  int prepRep
           
protected  double prepVar
           
protected  double[] u
           
 
Constructor Summary
RandomJames()
          Default constructor ( ij = 1802, kl = 9373 ).
RandomJames(int ij, int kl)
          Initializing constructor.
 
Method Summary
protected  void checkNormal(double mean, double variance, int rep)
          Pseudo-normal distribution parameter setup.
 double normalNumber(double mean, double variance, int rep)
          Pseudo-normal (Gaussian) distribution generator.
 void normalNumbers(double mean, double variance, int rep, double[] vec)
          Pseudo-normal (Gaussian) distribution generator.
 void normalNumbers(double mean, double variance, int rep, double[] vec, int from, int number)
          Pseudo-normal (Gaussian) distribution generator.
 int permutationFirst(int size)
          Random permutation setup.
 int permutationNext()
          Computes next permutation item.
 double randomDouble(double min, double max)
          Generates random double number from the given range.
 float randomFloat(float min, float max)
          Generates random float number from the given range.
 int randomInteger(int min, int max)
          Generates random integer number from the given range.
 void randomize()
          Undeterministic restart of a sequence (uses system time).
 double[] randomPointFromTriangle(double[] a, double[] b, double[] c, double[] result)
          Generates random point in the given triangle.
 void reset(int ij, int kl)
          Deterministic restart of a sequence.
 double[] uniformDirection(double minLat, double maxLat, double[] result)
          Uniformly generates random unit vector from the given latitude-defined strip.
 double uniformNumber()
          Uniform random number generator from [0,1].
 void uniformNumbers(double[] vec)
          Vector of uniform random numbers (from [0,1]).
 void uniformNumbers(double[] vec, int from, int number)
          Vector of uniform random numbers (from [0,1]).
 boolean validate()
          Validation test of a generator algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

u

protected double[] u

c

protected double c

cd

protected double cd

cm

protected double cm

i97

protected int i97

j97

protected int j97

prepMean

protected double prepMean

prepVar

protected double prepVar

norMul

protected double norMul

norAdd

protected double norAdd

prepRep

protected int prepRep

perm

protected int[] perm

permPtr

protected int permPtr

permSize

protected int permSize

ok

public boolean ok
Success flag.

Constructor Detail

RandomJames

public RandomJames(int ij,
                   int kl)
Initializing constructor.


RandomJames

public RandomJames()
Default constructor ( ij = 1802, kl = 9373 ).

Method Detail

checkNormal

protected void checkNormal(double mean,
                           double variance,
                           int rep)
Pseudo-normal distribution parameter setup.


reset

public void reset(int ij,
                  int kl)
Deterministic restart of a sequence.

Parameters:
ij - Random seed #1 [0,31328]
kl - Random seed #2 [0,30081]

randomize

public void randomize()
Undeterministic restart of a sequence (uses system time).


validate

public boolean validate()
Validation test of a generator algorithm.


uniformNumber

public double uniformNumber()
Uniform random number generator from [0,1].


uniformNumbers

public void uniformNumbers(double[] vec)
Vector of uniform random numbers (from [0,1]).


uniformNumbers

public void uniformNumbers(double[] vec,
                           int from,
                           int number)
Vector of uniform random numbers (from [0,1]).


normalNumber

public double normalNumber(double mean,
                           double variance,
                           int rep)
Pseudo-normal (Gaussian) distribution generator.


normalNumbers

public void normalNumbers(double mean,
                          double variance,
                          int rep,
                          double[] vec)
Pseudo-normal (Gaussian) distribution generator.


normalNumbers

public void normalNumbers(double mean,
                          double variance,
                          int rep,
                          double[] vec,
                          int from,
                          int number)
Pseudo-normal (Gaussian) distribution generator.


permutationFirst

public int permutationFirst(int size)
Random permutation setup.

Parameters:
size - Permutation size.
Returns:
The 1st item (0 to size - 1).
See Also:
permutationNext()

permutationNext

public int permutationNext()
Computes next permutation item.

Returns:
Next random item or -1 at the end.
See Also:
permutationFirst(int)

randomInteger

public final int randomInteger(int min,
                               int max)
Generates random integer number from the given range.


randomDouble

public final double randomDouble(double min,
                                 double max)
Generates random double number from the given range.


randomFloat

public final float randomFloat(float min,
                               float max)
Generates random float number from the given range.


randomPointFromTriangle

public final double[] randomPointFromTriangle(double[] a,
                                              double[] b,
                                              double[] c,
                                              double[] result)
Generates random point in the given triangle. Works in either dimension (2D, 3D).

Parameters:
a - Triangle vertex A.
b - Triangle vertex B.
c - Triangle vertex C.
result - Pre-allocated result array (can be null).
Returns:
Random point or null in case of failure.

uniformDirection

public final double[] uniformDirection(double minLat,
                                       double maxLat,
                                       double[] result)
Uniformly generates random unit vector from the given latitude-defined strip.
To generate arbitrary direction, use uniformDirection( -1.0, 1.0, result ), for direction from the upper hemisphere, use uniformDirection( 0.0, 1.0, result ).

Parameters:
minLat - Sine of the minimum latitude.
maxLat - Sine of the maximum latitude.
result - Pre-allocated result array (can be null).