java.util.Random
java.lang.Object
None
java.io.Serializable
JDK 1.0 or later
The Random class is a pseudo-random number generator. Pseudo-random numbers are generated by starting with a seed value and then using an algorithm to generate a sequence of numbers that appear to be random. The Random class uses a 48-bit seed and a linear congruential algorithm to modify the seed. As a consequence of this implementation, two Random instances that are constructed with the same seed value generate exactly the same sequence of numbers.
The Random class provides methods that return pseudo-random values for various primitive Java types. The Math.random() method is easier to use if you do not need to fine-tune the generation of random numbers.
public class java.util.Random extends java.lang.Object implements java.io.Serializable { // Constructors public Random(); public Random(long seed); // Instance Methods public void nextBytes(byte[] bytes); // New in 1.1 public double nextDouble(); public float nextFloat(); public synchronized double nextGaussian(); public int nextInt(); public long nextLong(); public synchronized void setSeed(long seed); // Protected Instance Methods protected synchronized int next(int bits); // New in 1.1 }
This constructor creates a Random object with the current time as its seed value.
The seed value to use.
This constructor creates a Random object with the given seed value.
New as of JDK 1.1
The byte array to fill.
This method fills the given array with pseudo-random byte values.
The next pseudo-random double value.
This method returns the next pseudo-random, uniformly distributed double value. The value is between 0.0 and 1.0 inclusive.
The next pseudo-random float value.
This method returns the next pseudo-random, uniformly distributed float value. The value is between 0.0 and 1.0 inclusive.
The next pseudo-random double value.
This method returns the next pseudo-random, Gaussian distributed double value. The value has a mean of 0.0 and a standard deviation of 1.0 from the random number sequence. The value is between -1.0 and 1.0.
The next pseudo-random int value.
This method returns the next pseudo-random, uniformly distributed int value.
The next pseudo-random long value.
This method returns the next pseudo-random, uniformly distributed long value.
The new seed value.
This method sets this Random object's seed value to the given value.
New as of JDK 1.1
The number of bits to generate.
The specified number of pseudo-random bits.
This method generates the given number of bits and returns them as an integer value. A subclass of Random should override this method, as it is used by all of the other random-number generation methods in the class.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
Math, Serializable
This HTML Help has been published using the chm2web software. |