RandomStringUtils: random(int count, int start, int end, boolean letters, boolean numbers, char[] chars, Random random)
/*
5) 8 char string using specific characters in an array >>>e1c2c2ce
*/
import org.apache.commons.lang.RandomStringUtils;
public class RandomStringUtilsTrial {
public static void main(String[] args) {
//Random 8 chars string using only the elements in the array aChars
//Only charcters between place 0 and 5 in the array can be used.
//Both letters and numbers are permitted
System.out.print(
"5) 8 char string using specific characters in an array >>>");
char[] aChars = new char[] { 'a', '1', 'c', '2', 'e', 'f', 'g' };
System.out.println(RandomStringUtils.random(8, 0, 5, true, true, aChars));
}
}
Apache-Common-Lang.zip( 248 k)Related examples in the same category