Package ovh.paulem.arcana.math
Class FastRandomUtils
java.lang.Object
ovh.paulem.arcana.math.FastRandomUtils
Utility class for generating random values using
This class provides methods for generating random booleans, bytes, integers, longs, doubles, and floats with optional range constraints and probability checks.
FastRandom.This class provides methods for generating random booleans, bytes, integers, longs, doubles, and floats with optional range constraints and probability checks.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleandoubleProbability(double probability) Determines if an event occurs based on a given probability (double).static booleanfloatProbability(float probability) Determines if an event occurs based on a given probability (float).
This method is less precise thandoubleProbability(double), but consumes less memorystatic booleanGenerates a random boolean value.
Can be used to simulate a coin flip or other random boolean events.static byte[]nextBytes(int count) Generates an array of random bytes.static doubleGenerates a random double within the range [0.0, Double.MAX_VALUE).static doublenextDouble(double startInclusive, double endExclusive) Generates a random double within a specified range.static floatGenerates a random float within the range [0.0, Float.MAX_VALUE).static floatnextFloat(float startInclusive, float endExclusive) Generates a random float within a specified range.static intnextInt()Generates a random integer within the range [0, Integer.MAX_VALUE).static intnextInt(int startInclusive, int endExclusive) Generates a random integer within a specified range.static longnextLong()Generates a random long within the range [0, Long.MAX_VALUE).static longnextLong(long startInclusive, long endExclusive) Generates a random long within a specified range.
-
Constructor Details
-
FastRandomUtils
public FastRandomUtils()
-
-
Method Details
-
floatProbability
public static boolean floatProbability(float probability) Determines if an event occurs based on a given probability (float).
This method is less precise thandoubleProbability(double), but consumes less memory- Parameters:
probability- the probability of the event occurring (0.0 to 1.0)- Returns:
- true if the event occurs, false otherwise
- Throws:
IllegalArgumentException- if the probability is negative or greater than 1
-
doubleProbability
public static boolean doubleProbability(double probability) Determines if an event occurs based on a given probability (double).- Parameters:
probability- the probability of the event occurring (0.0 to 1.0)- Returns:
- true if the event occurs, false otherwise
- Throws:
IllegalArgumentException- if the probability is negative or greater than 1
-
nextBoolean
public static boolean nextBoolean()Generates a random boolean value.
Can be used to simulate a coin flip or other random boolean events.- Returns:
- a random boolean
-
nextBytes
public static byte[] nextBytes(int count) Generates an array of random bytes.- Parameters:
count- the number of random bytes to generate- Returns:
- an array of random bytes
- Throws:
IllegalArgumentException- if the count is negative
-
nextInt
public static int nextInt(int startInclusive, int endExclusive) Generates a random integer within a specified range.- Parameters:
startInclusive- the inclusive lower bound of the rangeendExclusive- the exclusive upper bound of the range- Returns:
- a random integer within the range
- Throws:
IllegalArgumentException- if the range is invalid or negative
-
nextInt
public static int nextInt()Generates a random integer within the range [0, Integer.MAX_VALUE).- Returns:
- a random integer
-
nextLong
public static long nextLong(long startInclusive, long endExclusive) Generates a random long within a specified range.- Parameters:
startInclusive- the inclusive lower bound of the rangeendExclusive- the exclusive upper bound of the range- Returns:
- a random long within the range
- Throws:
IllegalArgumentException- if the range is invalid or negative
-
nextLong
public static long nextLong()Generates a random long within the range [0, Long.MAX_VALUE).- Returns:
- a random long
-
nextDouble
public static double nextDouble(double startInclusive, double endExclusive) Generates a random double within a specified range.- Parameters:
startInclusive- the inclusive lower bound of the rangeendExclusive- the exclusive upper bound of the range- Returns:
- a random double within the range
- Throws:
IllegalArgumentException- if the range is invalid or negative
-
nextDouble
public static double nextDouble()Generates a random double within the range [0.0, Double.MAX_VALUE).- Returns:
- a random double
-
nextFloat
public static float nextFloat(float startInclusive, float endExclusive) Generates a random float within a specified range.- Parameters:
startInclusive- the inclusive lower bound of the rangeendExclusive- the exclusive upper bound of the range- Returns:
- a random float within the range
- Throws:
IllegalArgumentException- if the range is invalid or negative
-
nextFloat
public static float nextFloat()Generates a random float within the range [0.0, Float.MAX_VALUE).- Returns:
- a random float
-