|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rit.util.Random
public abstract class Random
Class Random is the abstract base class for a pseudorandom number generator (PRNG) designed for use in parallel scientific programming. It differs from class java.util.Random in the following ways:
Each method for generating a number comes in two versions; for example:
public double nextDouble();
public double nextDouble (long skip);
Calling the second version with an argument skip is equivalent to
calling the first version skip times:
Random prng1 = Random.getInstance (1234L);
double x = prng1.nextDouble (1000);
Random prng2 = Random.getInstance (1234L);
double y;
for (int i = 0; i < 1000; ++ i)
y = prng2.nextDouble();
At the end of the above code fragment, x and y will have
the same value. However, calling nextDouble(1000) will typically be
much faster than calling nextDouble() 1000 times. Conversely,
nextDouble(1) is equivalent to nextDouble(), but the former
will typically be slower than the latter.
An instance of class Random can be serialized; for example, to checkpoint the state of the PRNG into a file and restore its state later.
The design of class Random is inspired in part by Coddington's JAPARA library. For further information, see P. Coddington and A. Newell, JAPARA -- A Java random number generator library for high-performance computing, in Proceedings of the 18th IEEE International Parallel and Distributed Processing Symposium (IPDPS'04), April 26-30, 2004, page 156.
| Constructor Summary | |
|---|---|
protected |
Random()
Construct a new PRNG. |
| Method Summary | |
|---|---|
static Random |
getInstance(long seed)
Construct a new PRNG with the given seed using the default algorithm. |
static Random |
getInstance(long seed,
String algorithm)
Construct a new PRNG with the given seed using the given algorithm. |
protected abstract long |
next()
Return the next 64-bit pseudorandom value in this PRNG's sequence. |
protected abstract long |
next(long skip)
Return the 64-bit pseudorandom value the given number of positions ahead in this PRNG's sequence. |
boolean |
nextBoolean()
Return the Boolean value from the next pseudorandom value in this PRNG's sequence. |
boolean |
nextBoolean(long skip)
Return the Boolean value from the pseudorandom value the given number of positions ahead in this PRNG's sequence. |
byte |
nextByte()
Return the byte value from the next pseudorandom value in this PRNG's sequence. |
byte |
nextByte(long skip)
Return the byte value from the next pseudorandom value the given number of positions ahead in this PRNG's sequence. |
char |
nextCharacter()
Return the character value from the next pseudorandom value in this PRNG's sequence. |
int |
nextCharacter(long skip)
Return the character value from the next pseudorandom value the given number of positions ahead in this PRNG's sequence. |
double |
nextDouble()
Return the double precision floating point value from the next pseudorandom value in this PRNG's sequence. |
double |
nextDouble(long skip)
Return the double precision floating point value from the pseudorandom value the given number of positions ahead in this PRNG's sequence. |
float |
nextFloat()
Return the single precision floating point value from the next pseudorandom value in this PRNG's sequence. |
float |
nextFloat(long skip)
Return the single precision floating point value from the pseudorandom value the given number of positions ahead in this PRNG's sequence. |
int |
nextInt(int n)
Return the integer value in the given range from the next pseudorandom value in this PRNG's sequence. |
int |
nextInt(int n,
long skip)
Return the integer value in the given range from the pseudorandom value the given number of positions ahead in this PRNG's sequence. |
int |
nextInteger()
Return the integer value from the next pseudorandom value in this PRNG's sequence. |
int |
nextInteger(long skip)
Return the integer value from the next pseudorandom value the given number of positions ahead in this PRNG's sequence. |
long |
nextLong()
Return the long value from the next pseudorandom value in this PRNG's sequence. |
long |
nextLong(long skip)
Return the long value from the next pseudorandom value the given number of positions ahead in this PRNG's sequence. |
short |
nextShort()
Return the short value from the next pseudorandom value in this PRNG's sequence. |
short |
nextShort(long skip)
Return the short value from the next pseudorandom value the given number of positions ahead in this PRNG's sequence. |
int |
nextUnsignedByte()
Return the unsigned byte value from the next pseudorandom value in this PRNG's sequence. |
int |
nextUnsignedByte(long skip)
Return the unsigned byte value from the next pseudorandom value the given number of positions ahead in this PRNG's sequence. |
int |
nextUnsignedShort()
Return the unsigned short value from the next pseudorandom value in this PRNG's sequence. |
int |
nextUnsignedShort(long skip)
Return the unsigned short value from the next pseudorandom value the given number of positions ahead in this PRNG's sequence. |
abstract void |
setSeed(long seed)
Set this PRNG's seed. |
void |
skip()
Skip one position ahead in this PRNG's sequence. |
void |
skip(long skip)
Skip the given number of positions ahead in this PRNG's sequence. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected Random()
| Method Detail |
|---|
public static Random getInstance(long seed)
If the "pj.prng" Java system property is specified, it gives the fully-qualified class name of the default PRNG class that the getInstance() method will construct. Specifying the "pj.prng" property will substitute a different PRNG algorithm into a program without needing to recompile.
If the "pj.prng" Java system property is not specified, the getInstance() method will return an instance of class DefaultRandom.
You can specify the "pj.prng" property on the Java command line like this:
java -Dpj.prng=MyOwnPrngClass . . .
Note: Depending on the PRNG algorithm, certain seed values may not be allowed. See the PRNG algorithm subclass for further information.
seed - Seed.
IllegalArgumentException - (unchecked exception) Thrown if the PRNG algorithm does not allow the
given seed value.
TypeNotPresentException - (unchecked exception) Thrown if a PRNG instance could not be
constructed. The chained exception gives further information about
the problem.
public static Random getInstance(long seed,
String algorithm)
Note: Depending on the PRNG algorithm, certain seed values may not be allowed. See the PRNG algorithm subclass for further information.
seed - Seed.algorithm - Fully-qualified name of the class to construct. This
must be a subclass of class Random.
IllegalArgumentException - (unchecked exception) Thrown if the PRNG algorithm does not allow the
given seed value.
TypeNotPresentException - (unchecked exception) Thrown if a PRNG instance could not be
constructed. The chained exception gives further information about
the problem.public abstract void setSeed(long seed)
Note: Depending on the PRNG algorithm, certain seed values may not be allowed. See the PRNG algorithm subclass for further information.
seed - Seed.
IllegalArgumentException - (unchecked exception) Thrown if the PRNG algorithm does not allow the
given seed value.public void skip()
public void skip(long skip)
skip - Number of positions to skip.public boolean nextBoolean()
public boolean nextBoolean(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.public byte nextByte()
public byte nextByte(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.public int nextUnsignedByte()
public int nextUnsignedByte(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.public char nextCharacter()
public int nextCharacter(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.public short nextShort()
public short nextShort(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.public int nextUnsignedShort()
public int nextUnsignedShort(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.public int nextInteger()
public int nextInteger(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.public int nextInt(int n)
n - Range of values to return.
IllegalArgumentException - (unchecked exception) Thrown if N <= 0.
public int nextInt(int n,
long skip)
n - Range of values to return.skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if N <= 0. Thrown if
skip <= 0.public long nextLong()
public long nextLong(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.public float nextFloat()
public float nextFloat(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.public double nextDouble()
public double nextDouble(long skip)
skip - Number of positions to skip.
IllegalArgumentException - (unchecked exception) Thrown if skip <= 0.protected abstract long next()
protected abstract long next(long skip)
skip - Number of positions to skip, assumed to be > 0.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||