Here you can find the source of getRandomString(int length)
public static String getRandomString(int length)
//package com.java2s; import java.util.Random; public class Main { private static char[] baseData = { '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' }; private static int baseDataLength = baseData.length; public static String getRandomString(int length) { char[] data = new char[length]; Random random = new Random(); for (int i = 0; i < length; i++) { data[i] = baseData[random.nextInt(baseDataLength)]; //data[i] = baseData[i]; }/* w ww.j a v a 2s .c o m*/ return new String(data); } }