javascript
private static final Random RANDOM = new Random();
// 生成指定范围的随机整数
public static int generateRandomInt(int min, int max) {
return RANDOM.nextInt(max - min + 1) + min;
}
public static void main(String[] args) {
Integer count = 5;
Integer randomInt = generateRandomInt(1, count);
System.out.println("生成的随机数是:"+randomInt);
}
结果