首页 > 其他 > 详细

Random:产生随机数的类

时间:2016-08-24 17:03:04      阅读:140      评论:0      收藏:0      [点我收藏+]
 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 }

 

Random:产生随机数的类

原文:http://www.cnblogs.com/jiangjianzhu/p/5803715.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!