Random random = new Random(); System.out.println(20+random.nextInt(80));
/* * 计算 min <= ,<= max 的随即整数,取到范围内各整数的概率相等。 */ import java.util.Random; public class MathTool { private static Random rnd = null; private MathTool() {} public static int getRandom(int min, int max) { if (min == max) return min; if (min > max) { int t = min; min = max; max = t; } if (rnd == null) rnd = new Random(); return rnd.nextInt(max - min + 1) + min; } }