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()); } } }