java Random类生成随机数
封装一个方法:
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; } }