Tuesday, April 10, 2001 03:33 PM
If you need JUST upper/lower case characters and/or numbers, but you do not want all the characters that are in the ASCII table between numbers, upper case letters and lower case (ie: ^ ` = and so on), you can use this other solution:
private final static String CHAR_LIST = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXWZabcdefghijklmnopqrstuvwxyz";
int strSize = 16;
StringBuffer rndStr = new StringBuffer();
for (int i=0; i rndStr.append(CHAR_LIST.charAt(random.nextInt(CHAR_LIST.length())));
System.out.println("-> " + rndStr.toString());
In this case, you can put in the static variable CHAR_LIST only the characters that you would like to use.