public class RandomGenerator extends RandomGenerator
Constructor and Description |
---|
RandomGenerator() |
RandomGenerator(long seed) |
Modifier and Type | Method and Description |
---|---|
static RandomGenerator |
getInstance() |
boolean |
nextBoolean()
Returns a random
boolean value that is true or
false with equal probability. |
boolean |
nextBoolean(double probability)
Returns a random
boolean value with the specified
probability. |
double |
nextDouble() |
double |
nextDouble(double min,
double max)
Returns the next random real number in the specified range.
|
int |
nextInt()
Returns the next random integer, which can be any legal integer value.
|
int |
nextInt(int max)
Returns the next random integer between 0 and
n -1,
inclusive. |
int |
nextInt(int min,
int max)
Returns the next random integer in the specified range.
|
static void |
rigBoolean(Boolean value) |
static void |
rigDouble(Double value) |
static void |
rigInt(Integer value) |
static void |
setAllSeed(Long seed) |
clearFixedIntegers, feedFixedIntegers, feedFixedIntegers, nextChoice, nextChoice, nextChoice, nextColor, setSharedSeed
public RandomGenerator()
public RandomGenerator(long seed)
public static void setAllSeed(Long seed)
public static RandomGenerator getInstance()
public static void rigBoolean(Boolean value)
public static void rigDouble(Double value)
public static void rigInt(Integer value)
public boolean nextBoolean()
RandomGenerator
boolean
value that is true
or
false
with equal probability. This method is in modern
implementations of the Random
class, but is missing from JDK
1.1.nextBoolean
in class RandomGenerator
public boolean nextBoolean(double probability)
RandomGenerator
boolean
value with the specified
probability. You can use this method to simulate an event that occurs
with a particular probability. For example, you could simulate the result
of tossing a coin like this:
String coinFlip = rgen.nextBoolean(0.5) ? "HEADS" : "TAILS";
nextBoolean
in class RandomGenerator
probability
- A value between 0 (impossible) and 1 (certain) indicating the
probabilitytrue
with probability p
public double nextDouble()
nextDouble
in class Random
public double nextDouble(double min, double max)
RandomGenerator
low
but always strictly less than
high
. You can use this method to generate continuous random
values. For example, you can set the variables x
and
y
to specify a random point inside the unit square as
follows:
double x = rgen.nextDouble(0.0, 1.0);
double y = rgen.nextDouble(0.0, 1.0);
nextDouble
in class RandomGenerator
min
- The low end of the rangemax
- The high end of the rangedouble
value d in the range
low
≤ d < high
public int nextInt()
RandomGenerator
nextInt
in class RandomGenerator
public int nextInt(int max)
RandomGenerator
n
-1,
inclusive. This method is in modern implementations of the
Random
class, but is missing from JDK 1.1.nextInt
in class RandomGenerator
public int nextInt(int min, int max)
RandomGenerator
rgen.nextInt(1, 6);
or a random decimal digit by calling
rgen.nextInt(0, 9);
nextInt
in class RandomGenerator
min
- The low end of the rangemax
- The high end of the rangeint
between low
and
high
, inclusive