physis.core.random
Class JavaUtilRandom
java.lang.Object
|
+--physis.core.random.Randomness
|
+--physis.core.random.JavaUtilRandom
- public class JavaUtilRandom
- extends Randomness
This is essentially the guts of java.util.Random as of jdk1.3.
Thu 31-May-2001 00:13 bush
from the header in java.util.Random:
An instance of this class is used to generate a stream of
pseudorandom numbers. The class uses a 48-bit seed, which is
modified using a linear congruential formula. (See Donald Knuth,
The Art of Computer Programming, Volume 2, Section 3.2.1.)
If two instances of Random are created with the same
seed, and the same sequence of method calls is made for each, they
will generate and return identical sequences of numbers. In order to
guarantee this property, particular algorithms are specified for the
class Random. Java implementations must use all the algorithms
shown here for the class Random, for the sake of absolute
portability of Java code. However, subclasses of class Random
are permitted to use other algorithms, so long as they adhere to the
general contracts for all the methods.
|
Method Summary |
static void |
main(java.lang.String[] args)
|
int |
next(int bits)
Generates the next pseudorandom number. |
void |
setSeed(long seed)
|
| Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
seed
private long seed
multiplier
private static final long multiplier
addend
private static final long addend
mask
private static final long mask
JavaUtilRandom
public JavaUtilRandom(long seed)
setSeed
public final void setSeed(long seed)
next
public final int next(int bits)
- Generates the next pseudorandom number. Subclass should
override this, as this is used by all other methods.
The general contract of next is that it returns an
int value and if the argument bits is between 1
and 32 (inclusive), then that many low-order bits of the
returned value will be (approximately) independently chosen bit
values, each of which is (approximately) equally likely to be
0 or 1. The method next is implemented
by class Random as follows:
synchronized protected int next(int bits) {
seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
return (int)(seed >>> (48 - bits));
}
This is a linear congruential pseudorandom number generator, as
defined by D. H. Lehmer and described by Donald E. Knuth in The
Art of Computer Programming, Volume 2: Seminumerical
Algorithms, section 3.2.1.
- Overrides:
next in class Randomness
- Parameters:
bits - random bits- Returns:
- the next pseudorandom value from this random number generator's sequence.
- Since:
- JDK1.1
main
public static void main(java.lang.String[] args)