Class RandomGenUtils

java.lang.Object
software.bluelib.utils.math.RandomGenUtils

public class RandomGenUtils extends Object
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:

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 Details

    • generateRandomInt

      public static int generateRandomInt(int pMin, int pMax)
      A Integer that generates a random integer between a specified minimum and maximum value (inclusive).
      Parameters:
      pMin - Integer - The minimum value (inclusive).
      pMax - Integer - The maximum value (inclusive).
      Returns:
      A random integer between pMin and pMax.
      Since:
      1.0.0
    • generateRandomDouble

      public static double generateRandomDouble(double pMin, double pMax)
      A Double that generates a random double between a specified minimum and maximum value (inclusive).
      Parameters:
      pMin - Double - The minimum value (inclusive).
      pMax - Double - The maximum value (inclusive).
      Returns:
      A random double between pMin and pMax.
      Since:
      1.0.0
    • generateRandomBoolean

      public static boolean generateRandomBoolean()
      A Boolean that generates a random boolean value.
      Returns:
      A random boolean value.
      Since:
      1.0.0
    • generateRandomString

      public static String generateRandomString(int pLength)
      A String that 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 - if pLength is negative.
      Since:
      1.0.0
    • generateRandomStringWithPrefix

      public static String generateRandomStringWithPrefix(String pPrefix, int pLength)
      A String that 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 - if pLength is negative.
      Since:
      1.0.0