Package software.bluelib.utils.math
Class RandomGenUtils
java.lang.Object
software.bluelib.utils.math.RandomGenUtils
A
class for generating random values of various types.
This class provides static methods to generate random integers, doubles, booleans, and alphanumeric strings. The methods offer flexibility in specifying the range or length for the generated values, and they ensure proper logging and error handling if invalid parameters are provided.
Key Methods:
generateRandomInt(int, int)- Generates a random integer between a specified minimum and maximum value (inclusive).generateRandomDouble(double, double)- Generates a random double between a specified minimum and maximum value (inclusive).generateRandomBoolean()- Generates a random boolean value.generateRandomString(int)- Generates a random alphanumeric string of a specified length.generateRandomStringWithPrefix(String, int)- Generates a random alphanumeric string with a specified prefix and length.
Each method logs errors using BaseLogger when invalid parameters are provided (e.g., negative lengths
or minimum values greater than maximum values) and returns default values (e.g., `0` for integers and `"unknown"` for strings)
in such cases.
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanABooleanthat generates a random boolean value.static doublegenerateRandomDouble(double pMin, double pMax) ADoublethat generates a random double between a specified minimum and maximum value (inclusive).static intgenerateRandomInt(int pMin, int pMax) AIntegerthat generates a random integer between a specified minimum and maximum value (inclusive).static StringgenerateRandomString(int pLength) AStringthat generates a random alphanumeric string of a specified length.static StringgenerateRandomStringWithPrefix(String pPrefix, int pLength) AStringthat generates a random alphanumeric string of a specified length with a specified prefix.
-
Method Details
-
generateRandomInt
public static int generateRandomInt(int pMin, int pMax) AIntegerthat generates a random integer between a specified minimum and maximum value (inclusive). -
generateRandomDouble
public static double generateRandomDouble(double pMin, double pMax) ADoublethat generates a random double between a specified minimum and maximum value (inclusive). -
generateRandomBoolean
public static boolean generateRandomBoolean()ABooleanthat generates a random boolean value.- Returns:
- A random boolean value.
- Since:
- 1.0.0
-
generateRandomString
AStringthat generates a random alphanumeric string of a specified length.- Parameters:
pLength-Integer- The length of the string to be generated.- Returns:
- A random alphanumeric string of the specified length.
- Throws:
IllegalArgumentException- ifpLengthis negative.- Since:
- 1.0.0
-
generateRandomStringWithPrefix
AStringthat generates a random alphanumeric string of a specified length with a specified prefix.- Parameters:
pPrefix-String- The prefix of the string.pLength-Integer- The length of the string to be generated.- Returns:
- A random alphanumeric string of the specified length with the specified prefix.
- Throws:
IllegalArgumentException- ifpLengthis negative.- Since:
- 1.0.0
-