Android Java生成隨機數的方法 – Android移動開發技術文章_手機開發 Android移動開發教學課程

此方法通過把當前時刻長整型數傳給Random對象,讓它產生的值隨著時間而變化。

 

www.aiwalls.com
Strings = ""; 
Random ran =new Random(System.currentTimeMillis()); 
for (inti = 0; i < 10; i++) { 
s =s + "\n" + ran.nextInt(100); 

Toast.makeText(UiTestActivity.this,"Random: \n" + s, Toast.LENGTH_LONG).show(); 
Strings = "";
Random ran =new Random(System.currentTimeMillis());
for (inti = 0; i < 10; i++) {
s =s + "\n" + ran.nextInt(100);
}
Toast.makeText(UiTestActivity.this,"Random: \n" + s, Toast.LENGTH_LONG).show();


 

摘自 michaelpp的專欄

發佈留言