public class Random extends Object
int
, long
, double
, and float
.
It follows the algorithms specified in the JRE javadoc.
This emulated version of Random is not serializable.Constructor and Description |
---|
Random()
Construct a random generator with the current time of day in milliseconds
plus a unique counter value 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. |
double |
nextGaussian()
Pseudo-randomly generates (approximately) a normally distributed
double value with mean 0.0 and a standard deviation value of 1.0
using the polar method of G. |
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)
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 double nextGaussian()
double
value with mean 0.0 and a standard deviation value of 1.0
using the polar method of G. E. P. Box, M. E. Muller, and G.
Marsaglia, as described by Donald E. Knuth in The Art of Computer
Programming, Volume 2: Seminumerical Algorithms, section 3.4.1,
subsection C, algorithm P.double
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)
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)
,
nextGaussian()
,
nextLong()
Copyright © 2018. All rights reserved.