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

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

其最基础的方法:

参数解读:

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

 

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注