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. }  

相关内容