Java Random随机数
Java Random随机数
java如果没有提供种子数,Random实例的种子数将是当前时间的毫秒数,可以通过System.currentTimeMillis()来获得当前时间的毫秒数。打开JDK的源代码,可以明确地看到
public Random() { this(System.currentTimeMillis()); }
- import java.util.*;
- public class Random {
- public static void main (String[] org) {
- for (int j=0; j<10; j++) {
- int d = (int)(Math.random()*100);
- System.out.println(d);
- }
- }
- }
评论暂时关闭