1 package test;
2 import java.util.Random;
3 /*
4 * Random类
5 * 此类用于产生随机数
6 * 构造方法:
7 * public Random():没有种子,用的是默认种子,是当前时间的毫秒值
8 * pubilc Random(long seed):给出固定的种子
9 * 给定种子后,每次得到的随机数是相同的
10 *
11 * 成员方法:
12 * public int nextInt() 返回的是int范围内的随机数
13 * public int nextInt(int n) 返回的是[0-n)范围内的随机数
14 * */
15
16 public class Test01 {
17 public static void main(String[] args) {
18 Random r=new Random(1111);
19 for(int i=0;i<10;i++){
20 int num=r.nextInt(100); //[0-100)
21 int num2=r.nextInt(100)+1; //[1-100]
22 //System.out.println(num);
23 System.out.println(num2);
24 }
25 }
26 }