java生成指定范围的随机数

 1 
 3 import java.util.Random;
 4 
 5 public class RandomTest {
 6     public static void main(String[] args) {
 7         int max=20;
 8         int min=10;
 9         Random random = new Random();
10 
11         int s = random.nextInt(max)%(max-min+1) + min;
12         System.out.println(s);
13     }
14 }
 1 package com;
 2 
 3 import java.util.Random;
 4 
 5 public class RandomTest {
 6     public static void main(String[] args) {
 7         int max = 80;
 8         int min = 60;
 9         int s = (int) (Math.random() * (max - min) + min);
10         System.out.println(s);
11     }
12 }
原文地址:https://www.cnblogs.com/dongwenbo/p/3342292.html