Java生成随机数的三种方式

package cn.zytao.taosir.random;

import java.util.Random;

public class RandomDemo {

    private static Integer byNewRandom() {
Random r=new Random();
return r.nextInt(100);
} private static Integer byMathRandom() {
int max=100,min=1;
return (int)(Math.random()*(max-min)+min);
} private static Integer byCurrentTimeMillis() {
int max=100,min=1;
long randomNum=System.currentTimeMillis();
return (int)(randomNum%(max-min)+min);
} public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
//System.out.println(byNewRandom());
//System.out.println(byMathRandom());
System.out.println(byCurrentTimeMillis());
}
}
}
上一篇:解决SQLite database is locked


下一篇:WCF、WebAPI、WCFREST和Web服务的差异 ASP.NETMVC和ASP.NETWebAPI的差异