Java by API/org.apache.commons.lang/RandomStringUtils
Содержание
- 1 RandomStringUtils: randomAlphabetic(int count)
- 2 RandomStringUtils: random(int count, boolean letters, boolean numbers)
- 3 RandomStringUtils: random(int count, int start, int end, boolean letters, boolean numbers, char[] chars, Random random)
- 4 RandomStringUtils: random(int count, String chars)
- 5 RandomStringUtils: randomNumeric(int count)
RandomStringUtils: randomAlphabetic(int count)
/*
3) 8 char Alphanumeric string >>>rq4CoAFZ
*/
import org.apache.rumons.lang.RandomStringUtils;
public class RandomStringUtilsTrial {
public static void main(String[] args) {
//Random 8 chars string Alphanumeric
System.out.print("3) 8 char Alphanumeric string >>>");
System.out.println(RandomStringUtils.randomAlphanumeric(8));
}
}
RandomStringUtils: random(int count, boolean letters, boolean numbers)
/*
2) 8 char string using letters but no numbers >>>PpdhkEBn
*/
import org.apache.rumons.lang.RandomStringUtils;
public class RandomStringUtilsTrial {
public static void main(String[] args) {
//Random 8 chars string where letters are enabled while numbers are not.
System.out.print("2) 8 char string using letters but no numbers >>>");
System.out.println(RandomStringUtils.random(8, true, false));
}
}
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.rumons.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));
}
}
RandomStringUtils: random(int count, String chars)
/*
1) 8 char string using chars ABCDEF >>>FDBDFADE
*/
import org.apache.rumons.lang.RandomStringUtils;
public class RandomStringUtilsTrial {
public static void main(String[] args) {
//Random 8 chars string from within the characters ABCDEF
System.out.print("1) 8 char string using chars ABCDEF >>>");
System.out.println(RandomStringUtils.random(8, "ABCDEF"));
}
}
RandomStringUtils: randomNumeric(int count)
/*
6) The two digit lucky number for the day is >>>17
*/
import org.apache.rumons.lang.RandomStringUtils;
public class RandomStringUtilsTrial {
public static void main(String[] args) {
// Begin Lottery code
System.out.print("6) The two digit lucky number for the day is >>>");
System.out.println(RandomStringUtils.randomNumeric(2));
// End Lottery code
}
}