public class PRNG
extends java.lang.Object
Random
interface can be used as the
random source.
PRNG
relies on an underlying source of randomness, and inherits
thread safety from the underlying implementation. Unless the underlying
implementation is known to be thread-safe, assume that PRNG
is not
thread-safe.
Modifier and Type | Method and Description |
---|---|
static java.util.Random |
getRandom()
Returns the source of randomness currently used.
|
static boolean |
nextBoolean()
Returns the next random, uniformly distributed
boolean value. |
static double |
nextDouble()
Returns the next random, uniformly distributed
double value
between 0.0 and 1.0. |
static double |
nextDouble(double min,
double max)
Returns the next random, uniformly distributed
double value
between min and max . |
static float |
nextFloat()
Returns the next random, uniformly distributed
float value
between 0.0 and 1.0. |
static float |
nextFloat(float min,
float max)
Returns the next random, uniformly distributed
float value
between min and max . |
static double |
nextGaussian()
Returns the next random, Gaussian distributed
double value with
mean 0.0 and standard deviation 1.0 . |
static double |
nextGaussian(double mean,
double stdev)
Returns the next random, Gaussian distributed
double value with
mean mean and standard deviation stdev . |
static int |
nextInt()
Returns the next random, uniformly distributed
int value between
Integer.MIN_VALUE and Integer.MAX_VALUE . |
static int |
nextInt(int n)
Returns the next random, uniformly distributed
int value between
0 (inclusive) and n (exclusive). |
static int |
nextInt(int min,
int max)
Returns the next random, uniformly distributed
int value between
min and max (both inclusive). |
static <T> T |
nextItem(java.util.List<T> list)
Returns a randomly selected item from the specified list.
|
static <T> T |
nextItem(java.util.Set<T> set)
Returns a randomly selected item from the specified set.
|
static void |
setRandom(java.util.Random random)
Sets the source of randomness to be used.
|
static void |
setSeed(long seed)
While the preferred method for seeding PRNGs is through the
setRandom method since methods providing more entropy may be
available
to specific implementations, this method is intended to provide a uniform
interface for setting the seed. |
static void |
shuffle(boolean[] array)
Shuffles the elements of the specified array using the same algorithm as
Collections.shuffle(java.util.List<?>) . |
static void |
shuffle(byte[] array)
Shuffles the elements of the specified array using the same algorithm as
Collections.shuffle(java.util.List<?>) . |
static void |
shuffle(double[] array)
Shuffles the elements of the specified array using the same algorithm as
Collections.shuffle(java.util.List<?>) . |
static void |
shuffle(float[] array)
Shuffles the elements of the specified array using the same algorithm as
Collections.shuffle(java.util.List<?>) . |
static void |
shuffle(int[] array)
Shuffles the elements of the specified array using the same algorithm as
Collections.shuffle(java.util.List<?>) . |
static <T> void |
shuffle(java.util.List<T> list)
Shuffles the elements of the specified list by invoking the
Collections.shuffle(java.util.List<?>) method with the internal Random in
this PRNG. |
static void |
shuffle(long[] array)
Shuffles the elements of the specified array using the same algorithm as
Collections.shuffle(java.util.List<?>) . |
static void |
shuffle(short[] array)
Shuffles the elements of the specified array using the same algorithm as
Collections.shuffle(java.util.List<?>) . |
static <T> void |
shuffle(T[] array)
Shuffles the elements of the specified array using the same algorithm as
Collections.shuffle(java.util.List<?>) . |
public static void setSeed(long seed)
setRandom
method since methods providing more entropy may be
available
to specific implementations, this method is intended to provide a uniform
interface for setting the seed.seed
- the new seedpublic static void setRandom(java.util.Random random)
random
- the source of randomness to be usedpublic static java.util.Random getRandom()
public static float nextFloat()
float
value
between 0.0 and 1.0.float
value
between 0.0 and 1.0public static float nextFloat(float min, float max)
float
value
between min
and max
.min
- the minimum value (inclusive)max
- the maximum value (exclusive)float
value
between min
and max
public static double nextDouble()
double
value
between 0.0 and 1.0.double
value
between 0.0 and 1.0public static double nextDouble(double min, double max)
double
value
between min
and max
.min
- the minimum value (inclusive)max
- the maximum value (exclusive)double
value
between min
and max
public static int nextInt()
int
value between
Integer.MIN_VALUE
and Integer.MAX_VALUE
.int
value between
Integer.MIN_VALUE
and Integer.MAX_VALUE
.public static int nextInt(int n)
int
value between
0
(inclusive) and n
(exclusive).n
- the maximum value (exclusive)int
value between
0
(inclusive) and n
(exclusive).public static int nextInt(int min, int max)
int
value between
min
and max
(both inclusive).min
- the minimum value (inclusive)max
- the maximum value (inclusive)int
value between
min
and max
(both inclusive).public static boolean nextBoolean()
boolean
value.boolean
value.public static double nextGaussian()
double
value with
mean 0.0
and standard deviation 1.0
.double
value with
mean 0.0
and standard deviation 1.0
.public static double nextGaussian(double mean, double stdev)
double
value with
mean mean
and standard deviation stdev
.mean
- the meanstdev
- the standard deviationdouble
value with
mean mean
and standard deviation stdev
.public static <T> void shuffle(T[] array)
Collections.shuffle(java.util.List<?>)
.T
- the type of element stored in the arrayarray
- the array to be shuffledpublic static void shuffle(double[] array)
Collections.shuffle(java.util.List<?>)
.array
- the array to be shuffledpublic static void shuffle(float[] array)
Collections.shuffle(java.util.List<?>)
.array
- the array to be shuffledpublic static void shuffle(long[] array)
Collections.shuffle(java.util.List<?>)
.array
- the array to be shuffledpublic static void shuffle(int[] array)
Collections.shuffle(java.util.List<?>)
.array
- the array to be shuffledpublic static void shuffle(short[] array)
Collections.shuffle(java.util.List<?>)
.array
- the array to be shuffledpublic static void shuffle(byte[] array)
Collections.shuffle(java.util.List<?>)
.array
- the array to be shuffledpublic static void shuffle(boolean[] array)
Collections.shuffle(java.util.List<?>)
.array
- the array to be shuffledpublic static <T> void shuffle(java.util.List<T> list)
Collections.shuffle(java.util.List<?>)
method with the internal Random
in
this PRNG.T
- the type of elements stored in the listlist
- the list to be shuffledpublic static <T> T nextItem(java.util.List<T> list)
T
- the type of the elements stored in the listlist
- the list from which the item is randomly selectedpublic static <T> T nextItem(java.util.Set<T> set)
T
- the type of the elements stored in the setset
- the set from which the item is randomly selectedCopyright 2009-2024 David Hadka and other contributors. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage.