Java tutorial
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { /** * Gets random string * * @return Random string */ public static String getRandomString() { final int length = 10; return getRandomString(length); } /** * Gets random string * * @param length String length * @return Random string */ public static String getRandomString(int length) { char[] chars = "ABCDEFGHIJKLMONPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray(); StringBuilder builder = new StringBuilder(); Random random = new Random(); for (int i = 0; i < length; i++) { char c = chars[random.nextInt(chars.length)]; builder.append(c); } return builder.toString(); } }