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

StringgenerateRandomString(int stringLength)
generate Random String
byte[] symbols = "abcdefghijklmnopqrstuvwxyz0123456789".getBytes();
Random random = new Random();
byte[] buffer = new byte[stringLength];
for (int i = 0; i < stringLength; i++) {
    buffer[i] = symbols[random.nextInt(symbols.length)];
return new String(buffer);
StringgenerateRandomString(int wordsLength, String separator)
Generates a string of random words with the supplied separator
Random rand = new Random();
String sb = "";
for (int i = 0; i < wordsLength; i++) {
    int randomWord = rand.nextInt(words.length);
    if (i != 0) {
        sb += separator;
    sb += words[randomWord];
...
StringgenerateRandomString(Random random, int length)
generate Random String
return random.ints(48, 122).filter(i -> (i < 57 || i > 65) && (i < 90 || i > 97)).mapToObj(i -> (char) i)
        .limit(length).collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
StringgenerateRandomString(Random random, int size)
generate Random String
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < size; i++) {
    char letter = (char) ((byte) 'A' + (byte) random.nextInt(26));
    stringBuilder.append(letter);
return stringBuilder.toString();
StringgenerateRandomString(Random rnd, char[] alphabet, int maxLength)
generate Random String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < (rnd.nextInt(maxLength) + 1); i++) {
    sb.append(alphabet[rnd.nextInt(alphabet.length)]);
return sb.toString();
StringgenerateRandomString(String str, int length)
generate Random String
String encoder = null;
if (str == null || str.trim().length() == 0) {
    encoder = _CHARTECER;
} else {
    encoder = str.trim();
StringBuilder randomString = new StringBuilder();
int limit = encoder.length();
...
StringgenRandomString()
Generates a random String of up to 10 characters
return genRandomString(rand.nextInt(10));
StringgenRandomString(final int length)
gen Random String
byte[] data = new byte[length];
for (int i = 0; i < data.length; i++) {
    data[i] = pickupAlphabet();
return new String(data);
StringgenRandomString(int count)
gen Random String
return genRandomString(count, DEFAULT_CHARS);
StringgetDefaultRandomName(String namePrefix)
get Default Random Name
if (namePrefix.length() > MAX_RESOURCE_LENGTH) {
    return String.format("%s%d", namePrefix.substring(0, MAX_RESOURCE_LENGTH).toLowerCase(),
            new Random().nextInt(1000000));
} else {
    return String.format("%s%d", namePrefix.toLowerCase(), new Random().nextInt(1000000));