Java random() 方法
random() 方法用於返回一個亂數,亂數範圍為 0.0 =< Math.random < 1.0。
語法
static double random()
參數
這是一個默認方法,不接受任何參數。
返回值
該方法返回 double 值。
實例
public class Test{
public static void main(String args[]){
System.out.println( Math.random() );
System.out.println( Math.random() );
}
}
編譯以上程式,輸出結果為:
0.5444085967267008 0.7960235983184115