Here you can find the source of randomString(int length)
public final static String randomString(int length)
//package com.java2s; /*//from w w w . j a v a 2s . co m This file is part of Peers, a java SIP softphone. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Copyright 2007, 2008, 2009, 2010 Yohann Martineau */ public class Main { public final static String randomString(int length) { String chars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIFKLMNOPRSTUVWXYZ" + "0123456789"; StringBuffer buf = new StringBuffer(length); for (int i = 0; i < length; ++i) { int pos = (int) Math.round(Math.random() * (chars.length() - 1)); buf.append(chars.charAt(pos)); } return buf.toString(); } }