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(); } }