Package craterdog.utils
Class RandomUtils
java.lang.Object
craterdog.utils.RandomUtils
This utility class contains static methods that generate random values for various purposes.
- Author:
- Derk Norton
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
generateRandomBytes
(int numberOfBytes) This utility method returns a byte array of the specified size containing randomly generated bytes.static double
This utility method returns a Gaussian distributed randomly generated double value.static int
pickRandomIndex
(int range) This utility method randomly selects an index from a range of indexes.static int
This utility method returns a randomly generated integer value.static double
This utility method returns an evenly distributed randomly generated double value.
-
Field Details
-
generator
-
-
Method Details
-
pickRandomInt
public static int pickRandomInt()This utility method returns a randomly generated integer value.- Returns:
- The randomly selected integer value.
-
pickRandomIndex
public static int pickRandomIndex(int range) This utility method randomly selects an index from a range of indexes. It is useful for randomly selecting an element of a list or array. For example:int randomIndex = RandomUtils.pickRandomIndex(list.size());
Note, the maximum possible index will be one less than the range (0..range-1).- Parameters:
range
- The size of the index range (including 0).- Returns:
- The randomly selected index value.
-
pickRandomProbability
public static double pickRandomProbability()This utility method returns an evenly distributed randomly generated double value.- Returns:
- The randomly selected double value.
-
pickRandomGaussian
public static double pickRandomGaussian()This utility method returns a Gaussian distributed randomly generated double value.- Returns:
- The randomly selected double value.
-
generateRandomBytes
public static byte[] generateRandomBytes(int numberOfBytes) This utility method returns a byte array of the specified size containing randomly generated bytes.- Parameters:
numberOfBytes
- The number of bytes in the desired byte array.- Returns:
- The byte array containing random bytes.
-