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

StringgetRandomAString(int min, int max)
get Random A String
String newstring = new String();
int i;
final char[] chars = { '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 strlen = (int) Math.floor(rand.nextDouble() * ((max - min) + 1));
...
ListgetRandomColors(final int size, final List colors)
Get RANDOM colors
final Set<String> res = new HashSet<>();
while (res.size() != size) {
    final String color = colors.get(RANDOM.nextInt(colors.size()));
    res.add(color);
return new ArrayList<>(res);
StringgetRandomElementOrCompound(String equation)
Accessor method used to return a random element in the chemical equation you specify.
ArrayList<String> list = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(equation);
while (st.hasMoreTokens()) {
    String element = st.nextToken();
    if (!element.equals("+") && !element.equals("->")) {
        list.add(element);
return list.get((int) (Math.random() * list.size()));
intgetRandomFromTier(int tier, String lvlRange)
get Random From Tier
Random r = new Random();
int Low = 1;
int High = 10;
int R;
switch (tier) {
case 1:
    Low = 1;
    if (lvlRange.equalsIgnoreCase("high"))
...
StringgetRandomNumberString(int length)
get Random Number String
Random generator = new Random();
char str[] = new char[length];
for (int i = 0; i < length; i++) {
    str[i] = CHARACTERS[51 + generator.nextInt(10)];
return new String(str);
StringgetRandomNumberString(int maxValue, int strLen)
get Random Number String
return intPadString(rnd.nextInt(maxValue), strLen);
StringgetRandomNumberStringBase36(int strLen)
get Random Number String Base
StringBuilder sb = new StringBuilder();
for (int i = 0; i < strLen; i++) {
    sb.append(digitsBase36.charAt(rnd.nextInt(36)));
return sb.toString();
StringgetRandomStr()
get Random Str
String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 16; i++) {
    int number = random.nextInt(base.length());
    sb.append(base.charAt(number));
return sb.toString();
...
StringgetRandomStr()
get Random Str
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 16; i++) {
    sb.append(RANDOM_STR.charAt(RANDOM.nextInt(RANDOM_STR.length())));
return sb.toString();
StringgetRandomStr()
Returns random string.
String DATE_FORMAT = "yyyy-MM-dd-HH-mm-ss";
DateFormat df = new SimpleDateFormat(DATE_FORMAT);
String rand = df.format(new Date(System.currentTimeMillis()));
return rand;