Java中的Random类

1、 构造方法
 a) public Random();没有种子,用的是默认种子,是当前时间的毫秒值
 b) public Random(long seed);给出指定的种子
  i. 给定种子后,每次得到的随机数相同
2、 成员方法
 a) public int nextInt();返回一个int范围的随机数
 b) public int nextInt(int n)返回的是[0,n]范围内的随机数
3、 用法
 a) Random r=new Random();
 b) int num =r.nextInt(100)

猜你喜欢

转载自blog.csdn.net/zfliu96/article/details/83411366