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, setSharedSeedpublic 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()
RandomGeneratorboolean 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 RandomGeneratorpublic boolean nextBoolean(double probability)
RandomGeneratorboolean 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 RandomGeneratorprobability - A value between 0 (impossible) and 1 (certain) indicating the
probabilitytrue with probability ppublic double nextDouble()
nextDouble in class Randompublic double nextDouble(double min,
double max)
RandomGeneratorlow 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 RandomGeneratormin - The low end of the rangemax - The high end of the rangedouble value d in the range
low ≤ d < highpublic int nextInt()
RandomGeneratornextInt in class RandomGeneratorpublic int nextInt(int max)
RandomGeneratorn-1,
inclusive. This method is in modern implementations of the
Random class, but is missing from JDK 1.1.nextInt in class RandomGeneratorpublic 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 RandomGeneratormin - The low end of the rangemax - The high end of the rangeint between low and
high, inclusive