RandomStringUtils工具类(java随机生成字符串)

使用RandomStringUtils可以选择生成随机字符串,可以是全字母,全数字,自定义生成字符等等...

其最基础的方法:

参数解读:

count:需要生成的随机串位数
letters:只要字母
numbers:只要数字
chars:自定义生成字符数组,如果为null,则为所有字符
start、end:选择字符开始生成的位置-----如果chars为null,start就是ASCII你想开始生成字符的位置,end同理;chars不为空的话,就是你自定义字符数组开始生成字符的位置
random:随机源
 
1、random(int count)       //在所有字符中随机生成6位
 
2、randomAscii(int count)      //在ASCII表中的打印字符中,即ASCII表32-127中随机生成6位
 
3、randomAlphabetic(int count)      //  生成只有字母的随机字符串,但是此方法的效率不高,不建议这样使用
 
4、randomAlphanumeric(int count)    //生成只有字母和数字的随机字符串,同样不建议这样使用
 
5、randomNumeric(int count)   // 生成只有数字的随机字符串,
 
6、random(int count, boolean letters, boolean numbers)    //可以指定是否要限定只生成字母或数字,上述三个方法都是调用此方法
 
7、random(int count, int start, int end, boolean letters, boolean numbers)    //可以指定字符集开始的位置,即不用搜索所有全部字符,同时可指定是否指定是否只生成字母或数字
 
8、random(int count, int start, int end, boolean letters, boolean numbers, char[] chars)    //用指定的字符集生成字符串
 
9、random(int count, String chars)   //使用指定字符串的字符生成新的随机字符串
 
10、String random(int count, char[] chars)   //用指定的字符集生成字符串,只是不能指定letters和numbers,其实还是调用了8
 
 
 

 

posted on 2018-08-13 11:24  zzzhouheng  阅读(9460)  评论(0编辑  收藏  举报

导航