package cn.itcast_01;
import java.util.Random;
/*
* Random类
* 此类用于产生随机数
* 构造方法;
* public Random()没有给出种子,用的是默认种子,是前当时间的毫秒值
* public Random(long seed)给出指定的种子
*
* 给定种子后,每次得到的随机数是相同的
* 成员方法:
* public int nextInt()返回的是int范围内的随机数
* public int nextInt(int n)返回的是[0,n)范围内的随机数
*/
public class Random概述和方法 {
public static void main(String[] args) {
//创建对象
Random r =new Random();
//没给种子
System.out.println(r.nextInt());
//给定种子
System.out.println("-----------");
System.out.println(r.nextInt(111111));
System.out.println(r.nextInt(111111));
System.out.println(r.nextInt(111111));
//给定种子后,每次得到的随机数是相同的
System.out.println("-----------");
System.out.println(r.nextInt(100));
System.out.println(r.nextInt(100));
System.out.println(r.nextInt(100));
}
}