cern.jet.random.tdouble.engine.RandomSeedGenerator Maven / Gradle / Ivy
Show all versions of parallelcolt Show documentation
/*
Copyright (C) 1999 CERN - European Organization for Nuclear Research.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
is hereby granted without fee, provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear in supporting documentation.
CERN makes no representations about the suitability of this software for any purpose.
It is provided "as is" without expressed or implied warranty.
*/
package cern.jet.random.tdouble.engine;
/**
* Deterministic seed generator for pseudo-random number generators. The sole
* purpose of this class is to decorrelate seeds and uniform random number
* generators. (If a generator would be used to generate seeds for itself, the
* result could be correlations.)
*
* This class has entirelly deterministic behaviour: Constructing two instances
* with the same parameters at any two distinct points in time will produce
* identical seed sequences. However, it does not (at all) generate uniformly
* distributed numbers. Do not use it as a uniformly distributed random number
* generator!
*
* Each generated sequence of seeds has a period of 109 numbers.
* Internally uses {@link RandomSeedTable}.
*
* @author [email protected]
* @version 1.0, 09/24/99
*/
public class RandomSeedGenerator extends cern.colt.PersistentObject {
/**
*
*/
private static final long serialVersionUID = 1L;
protected int row;
protected int column;
/**
* Constructs and returns a new seed generator.
*/
public RandomSeedGenerator() {
this(0, 0);
}
/**
* Constructs and returns a new seed generator; you normally won't need to
* use this method.
*
* The position [row,column] indicates the iteration starting point
* within a (virtual) seed matrix. The seed matrix is a n*m matrix with
* 1 + Integer.MAX_VALUE (virtual) rows and
* RandomSeedTable.COLUMNS columns. Successive calls to method
* nextSeed() will cycle over the given column, in ascending order:
* nextSeed() returns the seed
* s[row,column], s[row+1,column], ... s[Integer.MAX_VALUE,column], s[0,column], s[1,column], ...
*
* @param row
* should be in [0,Integer.MAX_VALUE].
* @param column
* should be in [0,RandomSeedTable.COLUMNS - 1].
*/
public RandomSeedGenerator(int row, int column) {
this.row = row;
this.column = column;
}
/**
* Prints the generated seeds for the given input parameters.
*/
public static void main(String args[]) {
int row = Integer.parseInt(args[0]);
int column = Integer.parseInt(args[1]);
int size = Integer.parseInt(args[2]);
new RandomSeedGenerator(row, column).print(size);
}
/**
* Returns the next seed.
*/
public int nextSeed() {
return RandomSeedTable.getSeedAtRowColumn(row++, column);
}
/**
* Prints the next size generated seeds.
*/
public void print(int size) {
System.out.println("Generating " + size + " random seeds...");
RandomSeedGenerator copy = (RandomSeedGenerator) this.clone();
for (int i = 0; i < size; i++) {
int seed = copy.nextSeed();
System.out.println(seed);
}
System.out.println("\ndone.");
}
}