Welcome 微信登录

首页 / 操作系统 / Linux / Java Random随机数

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