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

StringcreateRandomString()
create Random String
return String.valueOf(System.currentTimeMillis());
StringcreateRandomString(final int size)
Creates a random string filled with hex values.
String randomString = "";
while (randomString.length() < size) {
    randomString += Long.toHexString(random.nextLong());
return randomString.substring(0, size);
StringcreateRandomString(int length)
create Random String
char[] chars = new char[length];
for (int i = 0; i < length; i++) {
    chars[i] = createRandomChar();
return new String(chars);
ObjectcreateRandomWord(boolean startWithCapital)
create Random Word
StringBuffer buffer = new StringBuffer();
buffer.append(createRandomLetter(startWithCapital));
int size = randomSize(8);
for (int i = 1; i < size; ++i) {
    buffer.append(createRandomLetter(false));
return buffer.toString();
StringgenerateRandom(int num)
generate Random
char[] temp = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
        'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
        'U', 'V', 'W', 'X', 'Y', 'Z' };
int size = temp.length;
StringBuffer bu = new StringBuffer();
for (int i = 0; i < num; i++) {
    int r = (int) (Math.random() * size);
...
StringgenerateRandom(Integer digits)
generate Random
String s = "";
for (int i = 0; i < digits.intValue(); i++) {
    s = s + "0";
int multiplier = Integer.valueOf(1 + s).intValue();
int temp = (int) (Math.random() * multiplier);
s = String.valueOf(temp);
return s;
...
StringgenerateRandomChain(int length)
generate Random Chain
String pswd = "";
String key = NUMBERS + LETTERSUP + LETTERDOWN;
for (int i = 0; i < length; i++)
    pswd += (key.charAt((int) (Math.random() * key.length())));
return pswd;
StringgenerateRandomCharacters(int N)
Generates a random alpha-numeric character string of length N
return generateRandomCharacters(N, false);
StringgenerateRandomCode()
generate Random Code
final StringBuffer randomString = new StringBuffer();
for (int i = 0; i < 5; i++) {
    char c = 'A';
    c = (char) (c + (int) (Math.random() * 26));
    randomString.append(c);
return randomString.toString();
String[]generateRandomSentence()
generate Random Sentence
int dimension = r.nextInt(10);
String[] sentence = new String[dimension];
for (int j = 0; j < dimension; j++) {
    char c = (char) r.nextInt(10);
    sentence[j] = c + "-" + c + "-" + c;
return sentence;