优化cn.lili.common.utils.CommonUtil.getRandomNum方法逻辑
This commit is contained in:
parent
36ce7593a9
commit
de5e97ac3a
@ -1,7 +1,7 @@
|
||||
package cn.lili.common.utils;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* 通用工具
|
||||
@ -9,6 +9,8 @@ import java.util.UUID;
|
||||
*/
|
||||
public class CommonUtil {
|
||||
|
||||
public static final String BASE_NUMBER = "0123456789";
|
||||
|
||||
/**
|
||||
* 以UUID重命名
|
||||
* @param fileName 文件名称
|
||||
@ -24,12 +26,12 @@ public class CommonUtil {
|
||||
* 随机6位数生成
|
||||
*/
|
||||
public static String getRandomNum() {
|
||||
|
||||
Random random = new Random();
|
||||
int num = random.nextInt(999999);
|
||||
//不足六位前面补0
|
||||
String str = String.format("%06d", num);
|
||||
return str;
|
||||
StringBuilder sb = new StringBuilder(6);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int num = ThreadLocalRandom.current().nextInt(BASE_NUMBER.length());
|
||||
sb.append(BASE_NUMBER.charAt(num));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user