Class RandomMath
java.lang.Object
tk.airshipcraft.commonlib.utils.math.RandomMath
Utility class for generating random numbers within specified ranges.
- Since:
- 2023-10-11
- Version:
- 1.1.0
- Author:
- eerieXanthic, notzune
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Generates a random boolean value.static double
nextDouble
(double min, double max) Generates a random double within the specified range [min, max).static float
nextFloat
(float min, float max) Generates a random float within the specified range [min, max).static double
nextGaussian
(double mean, double stdDeviation) Generates a random double from a Gaussian (normal) distribution with the given mean and standard deviation.static int
nextInt
(int min, int max) Generates a random integer within the specified range [min, max].static long
nextLong
(long min, long max) Generates a random long within the specified range [min, max].
-
Method Details
-
nextDouble
public static double nextDouble(double min, double max) Generates a random double within the specified range [min, max).- Parameters:
min
- the minimum value (inclusive)max
- the maximum value (exclusive)- Returns:
- a random double within the specified range
- Throws:
IllegalArgumentException
- if min >= max
-
nextInt
public static int nextInt(int min, int max) Generates a random integer within the specified range [min, max].- Parameters:
min
- the minimum value (inclusive)max
- the maximum value (inclusive)- Returns:
- a random integer within the specified range
- Throws:
IllegalArgumentException
- if min > max
-
nextLong
public static long nextLong(long min, long max) Generates a random long within the specified range [min, max].- Parameters:
min
- the minimum value (inclusive)max
- the maximum value (inclusive)- Returns:
- a random long within the specified range
- Throws:
IllegalArgumentException
- if min > max
-
nextFloat
public static float nextFloat(float min, float max) Generates a random float within the specified range [min, max).- Parameters:
min
- the minimum value (inclusive)max
- the maximum value (exclusive)- Returns:
- a random float within the specified range
- Throws:
IllegalArgumentException
- if min >= max
-
nextGaussian
public static double nextGaussian(double mean, double stdDeviation) Generates a random double from a Gaussian (normal) distribution with the given mean and standard deviation.- Parameters:
mean
- the mean of the distributionstdDeviation
- the standard deviation of the distribution- Returns:
- a random double from the Gaussian distribution
-
nextBoolean
public static boolean nextBoolean()Generates a random boolean value.- Returns:
- a random boolean value
-