Java examples for java.lang:String Random
generate Random AN String
//package com.java2s; import java.util.Date; import java.util.Random; public class Main { public static void main(String[] argv) { int length = 42; System.out.println(generateRandomANString(length)); }// w ww . j av a 2 s .c o m private static Random random = new Random((new Date()).getTime()); public static String generateRandomANString(int length) { char[] values = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'A', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; String out = ""; for (int i = 0; i < length; i++) { int idx = random.nextInt(values.length); out += values[idx]; } return out; } }