封装一个方法:
import java.util.Random; public class RandomUtil { /** * nextInt(num) 产生[0 ~ (num-1)]的随机数, 闭区间 * @param Min * @param Max * @return */ public static int getRandomInt(int Min , int Max){ Random rand = new Random(); return rand.nextInt(Max - Min + 1) + Min; } }
原文地址:https://www.cnblogs.com/chenmz1995/p/12038132.html
时间: 2024-10-10 09:47:27