Java Utililty Methods Random String

List of utility methods to do Random String

Description

The list of methods to do Random String are organized into topic(s).

Method

StringgenerateRandomStr(final int length)
generate Random Str
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; i++) {
    builder.append(i);
return builder.toString();
StringgenerateRandomStr(int length)
Generate a random string.
String candidateChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < length; i++) {
    sb.append(candidateChars.charAt(random.nextInt(candidateChars.length())));
return sb.toString();
StringgenerateRandomString()
Gnerate a new random string
String str = "";
for (int i = 0; i < 10; i++)
    str += new Random().nextInt();
return str;
StringgenerateRandomString()
Generate a random String
String characters = "abcdefghijklmnopqrstuvwxyz123456789";
int length = generateRandomNumber();
char[] text = new char[length];
for (int i = 0; i < length; i++) {
    text[i] = characters.charAt(random.nextInt(characters.length()));
return new String(text);
StringgenerateRandomString()
generate Random String
return generateRandomString(RANDOM_STRING_COUNT);
StringgenerateRandomString()
generate Random String
Random rnd = new Random();
if (rnd.nextInt(3) == 0) {
    return "";
} else {
    return "test" + rnd.nextInt();
StringgenerateRandomString()
Generate random String , get its length , generate char list and append to random string generated.
StringBuffer strBfrRandom = new StringBuffer();
for (int i = 0; i < RANDOM_STRING_LENGTH; i++) {
    int intNumber = getRandomNumber();
    char character = CHAR_LIST.charAt(intNumber);
    strBfrRandom.append(character);
return strBfrRandom.toString();
StringgenerateRandomString()
Generates random string
int s = RAND.nextInt(CHARS.length());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < MIN_NO_OF_CHARS + s; ++i) {
    sb.append(CHARS.charAt(RAND.nextInt(CHARS.length())));
return sb.toString();
StringgenerateRandomString()
generate Random String
return Long.toHexString(Double.doubleToLongBits(Math.random()));
StringgenerateRandomString(final int minCharLen, final int maxCharLen)
generate Random String
if (minCharLen > maxCharLen) {
    throw new IllegalArgumentException(
            "Maximum Character Length must be larger than the Minimum Character Length");
StringBuilder builder = new StringBuilder();
generateCharacterList();
int len = (int) (Math.random() * (minCharLen - maxCharLen)) + minCharLen;
Random r = new Random();
...