Java Random String getRandomStringOfLetters(int length)

Here you can find the source of getRandomStringOfLetters(int length)

Description

Generates a random string of characters.

License

Open Source License

Declaration

public static String getRandomStringOfLetters(int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    private static final Random _RANDOM = new Random();

    /**// ww w . j ava2 s  .co m
     * Generates a random string of characters.
     */
    public static String getRandomStringOfLetters(int length) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < length; i++)
            buf.append(nextLetter());
        return buf.toString();
    }

    /**
     * Generates a random letter.
     */
    public static char nextLetter() {
        return (char) (nextInt(26) + 65);
    }

    /**
     * Generates a random integer between 0 (inclusive) and the requested bound (exclusive).
     */
    public static int nextInt(int bound) {
        return _RANDOM.nextInt(bound);
    }
}

Related

  1. getRandomString(Random random, int totalLength, int randomSectionLength)
  2. getRandomString(Random rnd, int minLength, int maxLength)
  3. getRandomString(String paramString, int paramLength)
  4. getRandomStringByLength(int length)
  5. getRandomStringForDate()
  6. getString(int length)
  7. getString(int length)
  8. getString(int length)
  9. getString(int n, int arg[])