Here you can find the source of getRandomString(int size)
public static String getRandomString(int size)
//package com.java2s; import java.util.Random; public class Main { private static final Random RANDOM = new Random(); private static final char[] CHARS = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' }; public static String getRandomString(int size) { StringBuilder s = new StringBuilder(size); int len = CHARS.length; for (int i = 0; i < size; i++) { int x = RANDOM.nextInt(); s.append(CHARS[(x < 0 ? -x : x) % len]); }//from ww w. j a v a 2 s .c o m return s.toString(); } public static String toString(byte[] bytes) { if (bytes == null || bytes.length == 0) { return ""; } StringBuffer buffer = new StringBuffer(); for (byte byt : bytes) { buffer.append((char) byt); } return buffer.toString(); } }