Here you can find the source of randomFileString()
static String randomFileString()
//package com.java2s; /* ******************************************************************* * Copyright (c) 1999-2001 Xerox Corporation, * 2002 Palo Alto Research Center, Incorporated (PARC). * All rights reserved. //w ww . j ava2 s .co m * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 * which accompanies this distribution and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Xerox/PARC initial implementation * ******************************************************************/ public class Main { final static String FILECHARS = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; /** @return semi-random String of length 6 usable as filename suffix */ static String randomFileString() { final double FILECHARS_length = FILECHARS.length(); final int LEN = 6; final char[] result = new char[LEN]; int index = (int) (Math.random() * 6d); for (int i = 0; i < LEN; i++) { if (index >= LEN) { index = 0; } result[index++] = FILECHARS.charAt((int) (Math.random() * FILECHARS_length)); } return new String(result); } }