当前位置:编程学习 > JAVA >>

Android Java生成随机数的方法

此方法通过把当前时刻长整型数传给Random对象,让它产生的值随着时间而变化。

 

www.zzzyk.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的专栏

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,