1.在j2se中使用Math.random()(產生0-1之間的double)方法:
如
public void numCreate(){ int array[] = new int[10]; for(int i=0;i<p>2.使用Random物件產生隨機數,他可以產生隨機的整數和浮點數。利用Random實例的next..()方法。一般情況選擇不帶種子的方式產生隨機數。如</p><pre class="brush:php;toolbar:false">public void numCreate(){ int array[] = new int[10]; for(int i=0;i<p>其中nextInt方法中的參數可以設定產生數字的範圍。在0(包括)和指定值(不包括)之間 。 </p>
以上是Java隨機數字如何產生的詳細內容。更多資訊請關注PHP中文網其他相關文章!