您的位置:首页 > 其它

* Random:产生随机数的类 *

2016-08-04 09:23 246 查看
package cn.itcast_01;

import java.util.Random;

/*

 * Random:产生随机数的类

 * 

 * 构造方法:

 * public Random():没有给种子,用的是默认种子,是当前时间的毫秒值

 * public Random(long seed):给出指定的种子

 *

 * 给定种子后,每次得到的随机数是相同的。

 *

 * 成员方法:

 * public int nextInt():返回的是int范围内的随机数

 * public int nextInt(int n):返回的是[0,n)范围的内随机数

 */

public class RandomDemo {
public static void main(String[] args) {
// 创建对象
// Random r = new Random();
Random r = new Random(1111);

for (int x = 0; x < 10; x++) {
// int num = r.nextInt();
int num = r.nextInt(100) + 1;
System.out.println(num);
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: