Skip to content

RandomGenUtils

Aram edited this page Jan 9, 2025 · 3 revisions

RandomGenUtils

Overview

The RandomGenUtils class in the software.bluelib.utils.math package provides methods to generate random values of various types. These methods include generating random integers, doubles, booleans, and alphanumeric strings, allowing flexible specification of range or length for the generated values.

Key Methods

  1. generateRandomInt(int, int)
    Generates a random integer within a specified range.

    int randomInt = RandomGenUtils.generateRandomInt(1, 10);
  2. generateRandomDouble(double, double)
    Generates a random double within a specified range.

    double randomDouble = RandomGenUtils.generateRandomDouble(0.5, 2.0);
  3. generateRandomBoolean()
    Generates a random boolean value.

    boolean randomBool = RandomGenUtils.generateRandomBoolean();
  4. generateRandomString(int)
    Generates a random alphanumeric string of a specified length.

    String randomString = RandomGenUtils.generateRandomString(8);
  5. generateRandomStringWithPrefix(String, int)
    Generates a random alphanumeric string with a specified prefix and length.

    String randomStringWithPrefix = RandomGenUtils.generateRandomStringWithPrefix("ID-", 10);

Usage Notes

  • Error Handling: If an invalid parameter is provided (e.g., negative lengths or minimum values greater than maximum values), the method throws an appropriate exception and logs an error message.
  • Utility Design: This class cannot be instantiated, as it contains a private constructor and only static methods.