public class Random
extends java.lang.Object
int
, long
, double
, and float
.Properties
,
PropertyResourceBundle
Constructor and Description |
---|
Random()
Construct a random generator with the current time of day in milliseconds
as the initial state.
|
Random(long seed)
Construct a random generator with the given
seed as the
initial state. |
Modifier and Type | Method and Description |
---|---|
protected int |
next(int bits)
Returns a pseudo-random uniformly distributed
int value of
the number of bits specified by the argument bits as
described by Donald E. |
boolean |
nextBoolean()
Returns the next pseudo-random, uniformly distributed
boolean value
generated by this generator. |
void |
nextBytes(byte[] buf)
Modifies the
byte array by a random sequence of byte s generated by this
random number generator. |
double |
nextDouble()
Generates a normally distributed random
double number between 0.0
inclusively and 1.0 exclusively. |
float |
nextFloat()
Generates a normally distributed random
float number between 0.0
inclusively and 1.0 exclusively. |
int |
nextInt()
Generates a uniformly distributed 32-bit
int value from
the random number sequence. |
int |
nextInt(int n)
Returns a new pseudo-random
int value which is uniformly distributed
between 0 (inclusively) and the value of n (exclusively). |
long |
nextLong()
Generates a uniformly distributed 64-bit integer value from
the random number sequence.
|
void |
setSeed(long seed)
Modifies the seed a using linear congruential formula presented in The
Art of Computer Programming, Volume 2, Section 3.2.1.
|
public Random()
setSeed(long)
public Random(long seed)
seed
as the
initial state.seed
- the seed that will determine the initial state of this random
number generator.setSeed(long)
protected int next(int bits)
int
value of
the number of bits specified by the argument bits
as
described by Donald E. Knuth in The Art of Computer Programming,
Volume 2: Seminumerical Algorithms, section 3.2.1.bits
- number of bits of the returned value.nextBytes(byte[])
,
nextDouble()
,
nextFloat()
,
nextInt()
,
nextInt(int)
,
nextLong()
public boolean nextBoolean()
boolean
value
generated by this generator.public void nextBytes(byte[] buf)
byte
array by a random sequence of byte
s generated by this
random number generator.buf
- non-null array to contain the new random byte
s.next(int)
public double nextDouble()
double
number between 0.0
inclusively and 1.0 exclusively.double
in the range [0.0 - 1.0)nextFloat()
public float nextFloat()
float
number between 0.0
inclusively and 1.0 exclusively.float
number between [0.0 and 1.0)nextDouble()
public int nextInt()
int
value from
the random number sequence.int
value.Integer.MAX_VALUE
,
Integer.MIN_VALUE
,
next(int)
,
nextLong()
public int nextInt(int n)
int
value which is uniformly distributed
between 0 (inclusively) and the value of n
(exclusively).n
- the exclusive upper border of the range [0 - n).int
.public long nextLong()
Integer.MAX_VALUE
,
Integer.MIN_VALUE
,
next(int)
,
nextInt()
,
nextInt(int)
public void setSeed(long seed)
seed
- the seed that alters the state of the random number generator.next(int)
,
Random()
,
Random(long)