Chinaunix首页 | 论坛 | 博客
  • 博客访问: 243312
  • 博文数量: 164
  • 博客积分: 60
  • 博客等级: 民兵
  • 技术积分: 1129
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-09 21:55
文章分类

全部博文(164)

文章存档

2017年(2)

2015年(67)

2014年(95)

我的朋友

分类: Java

2015-05-01 14:47:01



点击(此处)折叠或打开

  1. *
  2.  * Random:产生随机数的类
  3.  *
  4.  * 构造方法:
  5.  *         public Random():没有给种子,用的是默认种子,是当前时间的毫秒值
  6.  *        public Random(long seed):给出指定的种子
  7.  *
  8.  *        给定种子后,每次得到的随机数是相同的。
  9.  *
  10.  * 成员方法:
  11.  *         public int nextInt():返回的是int范围内的随机数
  12.  *        public int nextInt(int n):返回的是[0,n)范围的内随机数
  13.  */
  14. public class RandomDemo {
  15.     public static void main(String[] args) {
  16.         // 创建对象
  17.         // Random r = new Random();
  18.         Random r = new Random(1111);

  19.         for (int x = 0; x < 10; x++) {
  20.             // int num = r.nextInt();
  21.             int num = r.nextInt(100) + 1;
  22.             System.out.println(num);
  23.         }
  24.     }
  25. }

阅读(458) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~