Here you can find the source of generateRandomString()
public static String generateRandomString()
//package com.java2s; /**/*from w ww. j a v a 2 s. c o m*/ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.util.Random; public class Main { public static Random random = new Random(); /** * Generate a random String * * @return */ public static String generateRandomString() { String characters = "abcdefghijklmnopqrstuvwxyz123456789"; int length = generateRandomNumber(); char[] text = new char[length]; for (int i = 0; i < length; i++) { text[i] = characters.charAt(random.nextInt(characters.length())); } return new String(text); } /** * Generate a random number between 5 to 16 * * @return */ public static int generateRandomNumber() { Random randomGenerator = new Random(); return randomGenerator.nextInt(11) + 5; } }