Java examples for java.util:Random String
generate Random String
//package com.java2s; import java.util.Random; public class Main { public static void main(String[] argv) throws Exception { System.out.println(generateRandomString()); }//w w w . j a v a 2 s .c o m private static String generateRandomString() { StringBuilder generatedValue = new StringBuilder(); final String[] alphaNum = { "A", "B", "C", "D", "E", "W", "X", "Y", "Z", "f", "g", "h", "i", "j", "k", "l", "0", "1", "2", "3", "4", "5", "6", "7", "$", "^", "*", "@", "%", "~", "-" }; int length = alphaNum.length; Random r = new Random(); //24 for (int i = 0; i < 25; i++) { generatedValue.append(alphaNum[r.nextInt(length)]); } return generatedValue.toString(); } }