You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hai-oil-server/service/src/main/java/com/hfkj/common/utils/RandomUtils.java

31 lines
637 B

package com.hfkj.common.utils;
import java.util.Random;
/**
*
* @className: RandomUtils
* @author: HuRui
* @date: 2024/4/24
**/
public class RandomUtils {
/**
* 生成随机数
* @param length 长度
* @param zero 是否包含零
* @return
*/
public static String number(int length, boolean zero) {
String sl = "123456789";
if (zero) {
sl += "0";
}
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i < length ; i ++){
sb.append(sl.charAt(new Random().nextInt(sl.length())));
}
return sb.toString();
}
}