random() 方法用于返回一個隨機(jī)數(shù),隨機(jī)數(shù)范圍為 0.0 =< Math.random < 1.0。
static double random()
這是一個默認(rèn)方法,不接受參數(shù)。
此方法返回double。
下面是一個使用這個方法的例子 -
class Example { static void main(String[] args) { System.out.println( Math.random() ); System.out.println( Math.random() ); } }
當(dāng)我們運(yùn)行上面的程序,我們將得到以下結(jié)果 -
0.0543333676591804 0.3223824169137166
更多建議: