MOEA Framework 2.12
API Specification

org.moeaframework.core
Class PRNG

java.lang.Object
  extended by org.moeaframework.core.PRNG

public class PRNG
extends Object

Static methods for generating random or pseudo-random numbers. Any source of randomness implementing the 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.


Method Summary
static 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(List<T> list)
          Returns a randomly selected item from the specified list.
static void setRandom(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(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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setSeed

public 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.

Parameters:
seed - the new seed

setRandom

public static void setRandom(Random random)
Sets the source of randomness to be used.

Parameters:
random - the source of randomness to be used

getRandom

public static Random getRandom()
Returns the source of randomness currently used.

Returns:
the source of randomness currently used

nextFloat

public static float nextFloat()
Returns the next random, uniformly distributed float value between 0.0 and 1.0.

Returns:
the next random, uniformly distributed float value between 0.0 and 1.0

nextFloat

public static float nextFloat(float min,
                              float max)
Returns the next random, uniformly distributed float value between min and max.

Returns:
the next random, uniformly distributed float value between min and max

nextDouble

public static double nextDouble()
Returns the next random, uniformly distributed double value between 0.0 and 1.0.

Returns:
the next random, uniformly distributed double value between 0.0 and 1.0

nextDouble

public static double nextDouble(double min,
                                double max)
Returns the next random, uniformly distributed double value between min and max.

Returns:
the next random, uniformly distributed double value between min and max

nextInt

public static int nextInt()
Returns the next random, uniformly distributed int value between Integer.MIN_VALUE and Integer.MAX_VALUE .

Returns:
the next random, uniformly distributed int value between Integer.MIN_VALUE and Integer.MAX_VALUE.

nextInt

public static int nextInt(int n)
Returns the next random, uniformly distributed int value between 0 (inclusive) and n (exclusive).

Returns:
the next random, uniformly distributed int value between 0 (inclusive) and n (exclusive).

nextInt

public static int nextInt(int min,
                          int max)
Returns the next random, uniformly distributed int value between min and max (both inclusive).

Returns:
the next random, uniformly distributed int value between min and max (both inclusive).

nextBoolean

public static boolean nextBoolean()
Returns the next random, uniformly distributed boolean value.

Returns:
the next random, uniformly distributed boolean value.

nextGaussian

public static double nextGaussian()
Returns the next random, Gaussian distributed double value with mean 0.0 and standard deviation 1.0.

Returns:
the next random, Gaussian distributed double value with mean 0.0 and standard deviation 1.0.

nextGaussian

public static double nextGaussian(double mean,
                                  double stdev)
Returns the next random, Gaussian distributed double value with mean mean and standard deviation stdev.

Returns:
the next random, Gaussian distributed double value with mean mean and standard deviation stdev.

shuffle

public static <T> void shuffle(T[] array)
Shuffles the elements of the specified array using the same algorithm as Collections.shuffle(java.util.List).

Type Parameters:
T - the type of element stored in the array
Parameters:
array - the array to be shuffled

shuffle

public static void shuffle(double[] array)
Shuffles the elements of the specified array using the same algorithm as Collections.shuffle(java.util.List).

Parameters:
array - the array to be shuffled

shuffle

public static void shuffle(float[] array)
Shuffles the elements of the specified array using the same algorithm as Collections.shuffle(java.util.List).

Parameters:
array - the array to be shuffled

shuffle

public static void shuffle(long[] array)
Shuffles the elements of the specified array using the same algorithm as Collections.shuffle(java.util.List).

Parameters:
array - the array to be shuffled

shuffle

public static void shuffle(int[] array)
Shuffles the elements of the specified array using the same algorithm as Collections.shuffle(java.util.List).

Parameters:
array - the array to be shuffled

shuffle

public static void shuffle(short[] array)
Shuffles the elements of the specified array using the same algorithm as Collections.shuffle(java.util.List).

Parameters:
array - the array to be shuffled

shuffle

public static void shuffle(byte[] array)
Shuffles the elements of the specified array using the same algorithm as Collections.shuffle(java.util.List).

Parameters:
array - the array to be shuffled

shuffle

public static void shuffle(boolean[] array)
Shuffles the elements of the specified array using the same algorithm as Collections.shuffle(java.util.List).

Parameters:
array - the array to be shuffled

shuffle

public static <T> void shuffle(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.

Type Parameters:
T - the type of elements stored in the list
Parameters:
list - the list to be shuffled

nextItem

public static <T> T nextItem(List<T> list)
Returns a randomly selected item from the specified list.

Type Parameters:
T - the type of the elements stored in the list
Parameters:
list - the list from which the item is randomly selected
Returns:
a randomly selected item from the specified list

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!