Package utils

Class RandomStringGenerator

java.lang.Object
utils.RandomStringGenerator

public final class RandomStringGenerator extends Object
Utility class for generating random alphanumeric strings. Includes functionality to generate both general and unique strings. Note: Uniqueness is maintained in-memory for the life of the JVM.
  • Method Details

    • generateRandomString

      public static String generateRandomString(int length)
      Generates a random alphanumeric string of the specified length. Pure function: no global side effects.
      Parameters:
      length - non-negative length
      Returns:
      random string
      Throws:
      IllegalArgumentException - if length is negative
    • generateUniqueRandomString

      public static String generateUniqueRandomString(int length)
      Generates a unique random alphanumeric string of the specified length. Retries until a value is inserted into the concurrent set.
    • clearGeneratedForTests

      public static void clearGeneratedForTests()
      Test helper: clears the uniqueness set. Only use from tests to avoid unbounded growth across suites.