* 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);
}
}
}
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);
}
}
}
相关文章推荐
- JAVA基础MATH类的应用(Random产生自己想要的范围类的随机数解决方案)
- 设计一个类,该类中有一个方法,该方法使用Random类随机产生10个三位数字(如636)的随机数,并把产生的10个随机数存入数组中。然后在另一个类中输出这10个数
- java7新特性——使用ThreadLocalRandom产生并发随机数
- 用产生随机数的方法产生两个1位整数,求其和与积!Random
- Spark中组件Mllib的学习21之随机数-RandomRDD产生
- java7新特性——使用ThreadLocalRandom产生并发随机数
- Random不重复随机数的产生
- java中Random(long seed)方法与rRandom()方法的使用产生随机数
- Java中利用Math.random()产生服从泊松分布的随机数
- 让random在 4000 极短时间内产生的随机数不相同
- Java中利用Math.random()产生服从泊松分布的随机数
- c# Random太快产生的随机数会重复
- ORACLE 如何产生一个随机数:DBMS_RANDOM
- java7新特性——使用ThreadLocalRandom产生并发随机数
- C# Random对象短时间内产生不重复的随机数
- java中的随机数产生方式,random()方法和Random类
- 【转】让random在极短时间内产生的随机数不相同
- c++11随机数产生器default_random_engine
- Random产生随机数,不传入种子和传入种子的区别