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
🌐
Baeldung
baeldung.com › home › java › java string › java – generate random string
Java - Generate Random String | Baeldung
May 11, 2024 - @Test public void givenUsingApache_whenGeneratingRandomAlphanumericString_thenCorrect() { String generatedString = RandomStringUtils.randomAlphanumeric(10); System.out.println(generatedString); } And there we have it, creating bounded and unbounded strings with either plain Java, a Java 8 variant, or the Apache Commons Library. Through different implementation methods, we were able to generate bound and unbound strings using plain Java, a Java 8 variant, or the Apache Commons Library. In these Java examples, we used java.util.Random, but one point worth mentioning is that it is not cryptographically secure.
🌐
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)
Please note that the Apache Commons project provides a component dedicated to pseudo-random number generation, namely Commons RNG, that may be a better choice for applications with more stringent requirements (performance and/or correctness). ... 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.
🌐
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
import java.util.function.Supplier; · /** * Generates random {@link String}s. * <p> * Use {@link #secure()} to get the singleton instance based on {@link SecureRandom#SecureRandom()} which uses a secure random number generator implementing the · * default random number algorithm.
Author   apache
🌐
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.
🌐
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-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.
Find elsewhere
🌐
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.
🌐
Javadevcentral
javadevcentral.com › apache commons lang randomstringutils
Apache Commons Lang RandomStringUtils | Java Developer Central
November 8, 2021 - We will learn about the Apache Commons Lang RandomStringUtils class for generating random strings for simple use cases in this post.
🌐
Tabnine
tabnine.com › home page › code › java › org.apache.commons.lang.randomstringutils
org.apache.commons.lang.RandomStringUtils.random java code examples | Tabnine
/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of all characters.</p> * * @param count the length of random string to create * @return the random string ...
🌐
Vultr Docs
docs.vultr.com › java › examples › create-random-strings
Java Program to Create random strings | Vultr Docs
November 25, 2024 - Utilize the RandomStringUtils class which provides methods to create randomized strings.
🌐
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 - The code below show you how to use the Apache Commons-Lang RandomStringUtils class to generate some random string data. 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.
🌐
GitHub
github.com › apache › commons-lang › blob › master › src › test › java › org › apache › commons › lang3 › RandomStringUtilsTest.java
commons-lang/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java at master · apache/commons-lang
return Stream.of(RandomStringUtils.secure(), RandomStringUtils.secureStrong(), RandomStringUtils.insecure()); ... * Test for LANG-1286. Creates situation where old code would overflow a char and result in a code point outside the specified range. ... final String result = RandomStringUtils.random(2, start, end, false, false, null, fixedRandom);
Author   apache
🌐
CodeJava
codejava.net › coding › generate-random-strings-examples
Generate Random Strings in Java Examples
January 13, 2023 - Random String #1: !`;u!k=|Vc Random String #2: %%xB\B25ryhg|zS Random String #3: K/IzJ'}e@z$Vo%`'.Il)You can use this code example to generate random strong passwords. You can use the java.util.UUID class to generate random strings that are kind of Universally Unique Identifier (UUID).
🌐
Apache Commons
commons.apache.org › proper › commons-lang › apidocs › src-html › org › apache › commons › lang3 › RandomStringUtils.html
Random - Source code - The Apache Software Foundation
666 * </p> 667 * 668 * @deprecated ... Supplier<RandomUtils> random) { 676 this.random = random; 677 } 678 679 /** 680 * Creates a random string whose length is the number of characters specified....
🌐
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 - import java.util.Random; · /** * <p>Operations for random {@code String}s.</p> * <p>Currently <em>private high surrogate</em> characters are ignored. * These are Unicode characters that fall between the values 56192 (db80) * and 56319 (dbff) as we don't know how to handle them.
Author   addthis
🌐
Programiz
programiz.com › java-programming › examples › generate-random-string
Java Program to Create random strings
import java.util.Random; class Main { public static void main(String[] args) { // create a string of all characters String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // create random string builder StringBuilder sb = new StringBuilder(); // create an object of Random class Random random = new Random(); // specify length of random string int length = 7; for(int i = 0; i < length; i++) { // generate random index number int index = random.nextInt(alphabet.length()); // get character specified by index // from the string char randomChar = alphabet.charAt(index); // append the character to string builder sb.append(randomChar); } String randomString = sb.toString(); System.out.println("Random String is: " + randomString); } }
🌐
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 the generation of random strings, a very useful class can come in handy, namely RandomStringUtils from the Apache Commons Langs utilities library. It can be used for generating string that contain only letters, ...