import java.util.Random;
public class RandomNumber {
//1~10位间的随机数
public static Integer randomNumber(Integer num) {
if (num < 11) {
Integer subNum = new Double(Math.pow(10, num - 1)).intValue();
return new Random().nextInt(new Double(Math.pow(10, num)).intValue() - subNum) + subNum;
}
return 0;
}
Java 1~10位间的随机数工具类
于 2021-03-05 13:55:26 首次发布