Package utils
Class RandomStringGenerator
java.lang.Object
utils.RandomStringGenerator
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 Summary
Modifier and TypeMethodDescriptionstatic voidTest helper: clears the uniqueness set.static StringgenerateRandomString(int length) Generates a random alphanumeric string of the specified length.static StringgenerateUniqueRandomString(int length) Generates a unique random alphanumeric string of the specified length.
-
Method Details
-
generateRandomString
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
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.
-