Hello Word

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 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 
20         for (int x = 0; x < 10; x++) {
21             // int num = r.nextInt();
22             int num = r.nextInt(100) + 1;
23             System.out.println(num);
24         }
25     }
26 }

 

posted on 2016-08-25 16:05  该名称已被使用  阅读(258)  评论(0编辑  收藏  举报