public class Random
extends Object
Pseudo-random number generator.
- Author:
- Kai Burjack
-
Constructor Summary
Constructors
Create a new instance of
Random
and initialize it with a random seed.
Create a new instance of
Random
and initialize it with the given
seed
.
-
Method Summary
static long
float
Generate a uniformly distributed floating-point number in the half-open range [0, 1).
int
Generate a uniformly distributed integer in the half-open range [0, n).
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Random
public Random()
Create a new instance of
Random
and initialize it with a random seed.
-
Random
public Random(long seed)
Create a new instance of
Random
and initialize it with the given
seed
.
- Parameters:
seed
- the seed number
-
Method Details
-
newSeed
public static long newSeed()
-
nextFloat
public float nextFloat()
Generate a uniformly distributed floating-point number in the half-open range [0, 1).
- Returns:
- a random float in the range [0..1)
-
nextInt
public int nextInt(int n)
Generate a uniformly distributed integer in the half-open range [0, n).
- Parameters:
n
- the upper limit (exclusive) of the generated integer
- Returns:
- a random integer in the range [0..n)