4 changed files with 37 additions and 49 deletions
@ -0,0 +1,32 @@ |
|||||
|
package com.epmet; |
||||
|
|
||||
|
import com.epmet.commons.tools.constant.StrConstant; |
||||
|
|
||||
|
/** |
||||
|
* desc:随机生成字母 |
||||
|
* |
||||
|
* @author: LiuJanJun |
||||
|
* @date: 2022/3/1 5:16 下午 |
||||
|
* @version: 1.0 |
||||
|
*/ |
||||
|
public class StringRandomUtils { |
||||
|
|
||||
|
public static String getRandomStr(int length){ |
||||
|
String result = StrConstant.EPMETY_STR; |
||||
|
//小写字母范围: 97~122
|
||||
|
for (int i = 0; i < length; i++) { |
||||
|
int randomNumber = 97 + (int) (Math.random()* (122+1-97)); |
||||
|
result += (char)randomNumber; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
StringRandomUtils test = new StringRandomUtils(); |
||||
|
//测试
|
||||
|
for (int i = 0; i < 1000000; i++) { |
||||
|
System.out.println(getRandomStr(5)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue