Here you can find the source of generateRandomString(int length)
public static String generateRandomString(int length)
//package com.java2s; /*//from w w w .ja va2 s .co m * Copyright (C) 2012 Viettel Telecom. All rights reserved. * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.util.Random; public class Main { private static String RANDOM_STRING = "0123456789 _ aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"; public static String generateRandomString(int length) { Random rngRandom = new Random(); char[] text = new char[length]; int lengRnd = RANDOM_STRING.length(); for (int i = 0; i < length; i++) { text[i] = RANDOM_STRING.charAt(rngRandom.nextInt(lengRnd)); } return new String(text); } }