Random类
产生随机数的类
package com.gaowei_14;
import java.util.Random;
/*
* Random类:产生随机数
*
* 构造方法:
* public Random();
* 没有给种子,用的是默认种子,是当前时间的毫秒值
* public Random(long seed);
* 给出指定种子
*
* 成员方法:
* public int nextInt():
* 返回的是int范围内的随机数
* public int nextInt(int n):
* 返回的是[0,n)范围内的随机数
*
*/
public class RandomDemo1 {
public static void main(String[] args) {
//创建无种子对象
Random r = new Random();
int num = r.nextInt(100)+1; //返回1-100
System.out.println(num);
//创建带种子对象
Random r1 = new Random(1111);
int num1 = r1.nextInt(100)+1; //返回1-100
System.out.println(num1);
}
}
============================================
system类
该类包含一些有用的类字段和方法,它不能被实例化。