|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectnl.tudelft.simulation.jstats.streams.RandomNumberGenerator
The RandomNumberGenerator class provides an abstract for all pseudo random number generators.
(c) copyright 2004 Delft
University of Technology , the Netherlands.
See for project information
www.simulation.tudelft.nl
License of use: General Public
License (GPL) , no warranty
| Field Summary | |
protected long |
seed
the seed of the generator |
| Constructor Summary | |
RandomNumberGenerator()
constructs a new RandomNumberGenerator. |
|
RandomNumberGenerator(long seed)
constructs a new RandomNumberGenerator. |
|
| Method Summary | |
long |
getSeed()
returns the seed of the generator |
protected abstract long |
next(int bits)
returns the next value in the stream. |
boolean |
nextBoolean()
Returns the next pseudorandom, uniformly distributed boolean
value from this random number generator's sequence. |
double |
nextDouble()
Returns the next pseudorandom, uniformly distributed double
value between 0.0 and 1.0 from this random
number generator's sequence. |
float |
nextFloat()
Returns the next pseudorandom, uniformly distributed float
value between 0.0 and 1.0 from this random
number generator's sequence. |
int |
nextInt()
Returns the next pseudorandom, uniformly distributed int
value from this random number generator's sequence. |
int |
nextInt(int i,
int j)
Returns a pseudorandom, uniformly distributed int value between i (inclusive) and j, drawn from this random number generator's sequence. |
long |
nextLong()
Returns the next pseudorandom, uniformly distributed long
value from this random number generator's sequence. |
void |
reset()
resets the stream |
abstract void |
setSeed(long seed)
sets the seed of the generator |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected long seed
| Constructor Detail |
public RandomNumberGenerator()
public RandomNumberGenerator(long seed)
seed - the seed of the generator.| Method Detail |
public void reset()
StreamInterface
reset in interface StreamInterfaceStreamInterface.reset()protected abstract long next(int bits)
bits - the number of bits used
public boolean nextBoolean()
boolean
value from this random number generator's sequence. The general contract
of nextBoolean is that one boolean value is
pseudorandomly generated and returned. The values true and
false are produced with (approximately) equal probability.
The method nextBoolean is implemented by class Random
as follows:
public boolean nextBoolean()
{
return next(1) != 0;
}
nextBoolean in interface StreamInterfaceboolean
value from this random number generator's sequence.public double nextDouble()
double
value between 0.0 and 1.0 from this random
number generator's sequence.
The general contract of nextDouble is that one double value, chosen (approximately) uniformly from the range 0.0d (inclusive) to 1.0d (exclusive), is pseudorandomly generated and returned. All 2 64 possible float values of the form m x 2 -64 , where m is a positive integer less than 2 64 , are produced with (approximately) equal probability.
nextDouble in interface StreamInterfacedouble
value between 0.0 and 1.0 from this
random number generator's sequence.public float nextFloat()
float
value between 0.0 and 1.0 from this random
number generator's sequence.
The general contract of nextFloat is that one float value, chosen (approximately) uniformly from the range 0.0f (inclusive) to 1.0f (exclusive), is pseudorandomly generated and returned. All 2 24 possible float values of the form m x  2 -24 , where m is a positive integer less than 2 24 , are produced with (approximately) equal probability. The method nextFloat is implemented by class Random as follows:
public float nextFloat() {
return next(24) / ((float)(1 < < 24));
}
The hedge "approximately" is used in the foregoing
description only because the next method is only approximately an
unbiased source of independently chosen bits. If it were a perfect source
or randomly chosen bits, then the algorithm shown would choose
float values from the stated range with perfect uniformity.
nextFloat in interface StreamInterfacefloat
value between 0.0 and 1.0 from this
random number generator's sequence.public int nextInt()
int
value from this random number generator's sequence. The general contract
of nextInt is that one int value is pseudorandomly
generated and returned. All 2 32
possible int values are produced with (approximately) equal
probability. The method nextInt is implemented by class
Random as follows:
public int nextInt()
{
return next(32);
}
nextInt in interface StreamInterfaceint
value from this random number generator's sequence.
public int nextInt(int i,
int j)
nextInt in interface StreamInterfacei - the lower valuej - the higher value
public long nextLong()
long
value from this random number generator's sequence. The general contract
of nextLong is that one long value is pseudorandomly generated
and returned. All 2 64 possible
long values are produced with (approximately) equal
probability. The method nextLong is implemented by class
Random as follows:
public long nextLong() {
return ((long)next(32) < < 32) + next(32);
}
nextLong in interface StreamInterfacelong
value from this random number generator's sequence.public abstract void setSeed(long seed)
StreamInterface
setSeed in interface StreamInterfaceseed - the new seedStreamInterface.setSeed(long)public long getSeed()
StreamInterface
getSeed in interface StreamInterfaceStreamInterface.getSeed()public java.lang.String toString()
Object.toString()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||