A random sequence of strings will always have a possibility of repeating, otherwise it's not really random. RandomStringUtils is not really random, but it's trying to be as close to random as it can be, which seems contrary to your goal. If you must use randomly generated keys, then you should at least use java.util.UUID.randomUUID because that is made to be used that way.

You may find this link interesting: Generating unique IDs

Answer from Geo on Stack Overflow
🌐
Apache Commons
commons.apache.org › proper › commons-lang › apidocs › org › apache › commons › lang3 › RandomStringUtils.html
RandomStringUtils (Apache Commons Lang 3.20.0 API)
RandomStringUtils instances should NOT be constructed in standard programming. Instead, the class should be used as RandomStringUtils.random(5);. This constructor is public to permit tools that require a JavaBean instance to operate.
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-3.9 › org › apache › commons › lang3 › RandomStringUtils.html
RandomStringUtils (Apache Commons Lang 3.9 API)
RandomStringUtils instances should NOT be constructed in standard programming. Instead, the class should be used as RandomStringUtils.random(5);. This constructor is public to permit tools that require a JavaBean instance to operate.
🌐
Baeldung
baeldung.com › home › java › java string › java – generate random string
Java - Generate Random String | Baeldung
May 11, 2024 - @Test public void givenUsingApache_whenGeneratingRandomStringBounded_thenCorrect() { int length = 10; boolean useLetters = true; boolean useNumbers = false; String generatedString = RandomStringUtils.random(length, useLetters, useNumbers); System.out.println(generatedString); } So instead of all the low-level code in the Java example, this one is done with a simple one-liner.
🌐
Javadevcentral
javadevcentral.com › apache commons lang randomstringutils
Apache Commons Lang RandomStringUtils | Java Developer Central
November 8, 2021 - We can use the Apache Commons Lang RandomStringUtils for generating random strings. It is used for simple cases only and the Random instance it uses is not cryptographically secure.
🌐
GitHub
github.com › apache › commons-lang › blob › master › src › main › java › org › apache › commons › lang3 › RandomStringUtils.java
commons-lang/src/main/java/org/apache/commons/lang3/RandomStringUtils.java at master · apache/commons-lang
* be used as {@code RandomStringUtils.random(5);}. * * <p> * This constructor is public to permit tools that require a JavaBean instance to operate. * </p> * * @deprecated TODO Make private in 4.0. */ @Deprecated ·
Author   apache
🌐
Educative
educative.io › answers › what-is-randomstringutilsrandomalphanumeric-in-java
What is RandomStringUtils.randomAlphanumeric() in Java?
the methods in Java that can be called without creating an object of the class. method of the RandomStringUtils class that is used to generate random strings consisting of alphanumeric characters.
🌐
Apache Commons
commons.apache.org › proper › commons-lang › jacoco › org.apache.commons.lang3 › RandomStringUtils.java.html
RandomStringUtils.java - Apache Commons
* </p> * * @deprecated TODO Make private in 4.0. */ @Deprecated public RandomStringUtils() { this(SECURE_SUPPLIER); } private RandomStringUtils(final Supplier<RandomUtils> random) { this.random = random; } /** * Creates a random string whose length is the number of characters specified.
🌐
Educative
educative.io › answers › what-is-randomstringutilsrandomalphabetic-in-java
What is RandomStringUtils.randomAlphabetic() in Java?
the methods in Java that can be called without creating an object of the class. method of the RandomStringUtils class which is used to generate random strings consisting of alphabetic characters.
Find elsewhere
🌐
Kodejava
kodejava.org › how-do-i-generate-a-random-alpha-numeric-string
How do I generate a random alphanumeric string? - Learn Java by Examples
June 3, 2024 - package org.kodejava.commons.lang; import org.apache.commons.lang3.RandomStringUtils; public class RandomStringUtilsDemo { public static void main(String[] args) { // Creates a 64-chars length random string of number. String result = RandomStringUtils.random(64, false, true); System.out.println("random = " + result); // Creates a 64-chars length of random alphabetic string.
🌐
Educative
educative.io › answers › what-is-randomstringutilsrandomnumeric-in-java
What is RandomStringUtils.randomNumeric() in Java?
describes the methods in Java that can be called without creating an object of the class method of the RandomStringUtils class which is used to generate random string consisting of numeric characters.
🌐
imalittletester
imalittletester.com › 2014 › 05 › 05 › useful-generating-random-strings-with-randomstringutils
Useful: generating random strings with RandomStringUtils | imalittletester
June 29, 2017 - When writing tests that require ... Commons Langs utilities library. It can be used for generating string that contain only letters, only numbers, both, these and other characters....
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-2.6 › org › apache › commons › lang › RandomStringUtils.html
RandomStringUtils (Commons Lang 2.6 API)
January 9, 2011 - RandomStringUtils instances should NOT be constructed in standard programming. Instead, the class should be used as RandomStringUtils.random(5);. This constructor is public to permit tools that require a JavaBean instance to operate.
🌐
DZone
dzone.com › data engineering › data › how to generate a random string in java using apache commons lang
How to Generate a Random String in Java using Apache Commons Lang
May 6, 2014 - System.out.println(RandomStringUtils.random(10,new char[]{'a','b','c','d'})); Strings Data Types Java (programming language) Published at DZone with permission of Faheem Sohail, DZone MVB. See the original article here. Opinions expressed by DZone contributors are their own.
🌐
Apache Commons
commons.apache.org › proper › commons-lang › javadocs › api-3.7 › org › apache › commons › lang3 › RandomStringUtils.html
RandomStringUtils (Apache Commons Lang 3.7 API)
RandomStringUtils instances should NOT be constructed in standard programming. Instead, the class should be used as RandomStringUtils.random(5);. This constructor is public to permit tools that require a JavaBean instance to operate.
🌐
Javadoc.io
javadoc.io › doc › org.apache.commons › commons-lang3 › 3.8 › org › apache › commons › lang3 › RandomStringUtils.html
RandomStringUtils (Apache Commons Lang 3.8 API)
https://javadoc.io/doc/org.apache.commons/commons-lang3 · Current version 3.8 · https://javadoc.io/doc/org.apache.commons/commons-lang3/3.8 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org.apache.commons/commons-lang3/3.8/package-list ·
🌐
Javadoc.io
javadoc.io › doc › org.apache.commons › commons-lang3 › 3.6 › org › apache › commons › lang3 › RandomStringUtils.html
RandomStringUtils (Apache Commons Lang 3.6 API)
https://javadoc.io/doc/org.apache.commons/commons-lang3 · Current version 3.6 · https://javadoc.io/doc/org.apache.commons/commons-lang3/3.6 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org.apache.commons/commons-lang3/3.6/package-list ·
🌐
GitHub
github.com › addthis › stream-lib › blob › master › src › test › java › org › apache › commons › lang3 › RandomStringUtils.java
stream-lib/src/test/java/org/apache/commons/lang3/RandomStringUtils.java at master · addthis/stream-lib
July 7, 2020 - * {@code RandomStringUtils.random(5);}.</p> * <p/> * <p>This constructor is public to permit tools that require a JavaBean instance · * to operate.</p> */ public RandomStringUtils() { super(); } · // Random · //----------------------------------------------------------------------- ·
Author   addthis
🌐
Elias Nogueira
eliasnogueira.com › reasons-to-avoid-randomstringutils-for-test-data-generation
Reasons to avoid RandomStringUtils for test data generation
October 10, 2021 - Here we will see a common usage from Java developers: the RamdomStringUItils and how it might not be the best choice for automatic data generation. By the way, I recommend automatic data generation in the tests using the Test Data Factory approach, and you can find an example here in my blog: Test Data Factory: Why and How to Use. The examples described here are simple, without the usage of the Test Data Factory, and will show you why the RandomStringUtils ...