Here you can find the source of randomString(int minLength, int maxLength)
public static String randomString(int minLength, int maxLength)
//package com.java2s; //License from project: Apache License import java.util.Random; import java.util.concurrent.ThreadLocalRandom; public class Main { public static String randomString(int minLength, int maxLength) { Random random = ThreadLocalRandom.current(); return randomString(minLength, maxLength, random); }/* w w w. j a v a 2s. c o m*/ public static String randomString(int minLength, int maxLength, Random random) { return randomStringBuilder(minLength, maxLength, random).toString(); } public static StringBuilder randomStringBuilder(int minLength, int maxLength, Random random) { int length; if (minLength > maxLength) throw new IllegalArgumentException(); if (minLength == maxLength) { length = minLength; } else { length = minLength + random.nextInt(maxLength - minLength); } StringBuilder sb = new StringBuilder(length); for (int i = length; i > 0; --i) { sb.append((char) (random.nextInt('Z' - 'A') + 'A')); } return sb; } }