Java by API/org.apache.commons.lang/RandomStringUtils — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 17:47, 31 мая 2010
Содержание
- 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)
<source lang="java">
/* 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)); }
}
</source>
RandomStringUtils: random(int count, boolean letters, boolean numbers)
<source lang="java">
/* 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)); }
}
</source>
RandomStringUtils: random(int count, int start, int end, boolean letters, boolean numbers, char[] chars, Random random)
<source lang="java">
/* 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)); }
}
</source>
RandomStringUtils: random(int count, String chars)
<source lang="java">
/*
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")); }
}
</source>
RandomStringUtils: randomNumeric(int count)
<source lang="java">
/* 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 }
}
</source>