// 产生5位长度的随机字符串,中文环境下是乱码
String r = RandomStringUtils.random(5);
System.out.println(r);
// 使用指定的字符生成5位长度的随机字符串
r = RandomStringUtils.random(5, new char[] { 'a', 'b', 'c', 'd', 'e',
'f', '1', '2', '3' });
System.out.println(r);
// 生成指定长度的字母和数字的随机组合字符串
r = RandomStringUtils.randomAlphanumeric(5);
System.out.println(r);
// 生成随机数字字符串
r = RandomStringUtils.randomNumeric(5);
System.out.println(r);
// 生成随机[a-z]字符串,包含大小写
r = RandomStringUtils.randomAlphabetic(5);
System.out.println(r);
// 生成从ASCII 32到126组成的随机字符串
r = RandomStringUtils.randomAscii(4);
System.out.println(r);
-
Constructor and Description RandomStringUtils()
RandomStringUtils
instances should NOT be constructed in standard programming.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static String
random(int count)
Creates a random string whose length is the number of characters specified.
static String
random(int count, boolean letters, boolean numbers)
Creates a random string whose length is the number of characters specified.
static String
random(int count, char... chars)
Creates a random string whose length is the number of characters specified.
static String
random(int count, int start, int end, boolean letters, boolean numbers)
Creates a random string whose length is the number of characters specified.
static String
random(int count, int start, int end, boolean letters, boolean numbers, char... chars)
Creates a random string based on a variety of options, using default source of randomness.
static String
random(int count, int start, int end, boolean letters, boolean numbers, char[] chars, Random random)
Creates a random string based on a variety of options, using supplied source of randomness.
static String
random(int count, String chars)
Creates a random string whose length is the number of characters specified.
static String
randomAlphabetic(int count)
Creates a random string whose length is the number of characters specified.
static String
randomAlphabetic(int minLengthInclusive, int maxLengthExclusive)
Creates a random string whose length is between the inclusive minimum and the exclusive maximum.
static String
randomAlphanumeric(int count)
Creates a random string whose length is the number of characters specified.
static String
randomAlphanumeric(int minLengthInclusive, int maxLengthExclusive)
Creates a random string whose length is between the inclusive minimum and the exclusive maximum.
static String
randomAscii(int count)
Creates a random string whose length is the number of characters specified.
static String
randomAscii(int minLengthInclusive, int maxLengthExclusive)
Creates a random string whose length is between the inclusive minimum and the exclusive maximum.
static String
randomGraph(int count)
Creates a random string whose length is the number of characters specified.
static String
randomGraph(int minLengthInclusive, int maxLengthExclusive)
Creates a random string whose length is between the inclusive minimum and the exclusive maximum.
static String
randomNumeric(int count)
Creates a random string whose length is the number of characters specified.
static String
randomNumeric(int minLengthInclusive, int maxLengthExclusive)
Creates a random string whose length is between the inclusive minimum and the exclusive maximum.
static String
randomPrint(int count)
Creates a random string whose length is the number of characters specified.
static String
randomPrint(int minLengthInclusive, int maxLengthExclusive)
Creates a random string whose length is between the inclusive minimum and the exclusive maximum.