//随机生成10个0-10之间的数字publicclassRandom{publicstaticvoidmain(String[] args){for(int i =0; i <10; i++){//java.lang.Math类 random()方法,是返回大于0 小于1的随机小数(double)System.out.printf("%.0f%n",Math.random()*10);}}}
运行结果:
460109864310
for(int i =0; i <10; i++){//java.lang.Math类 random()方法,是返回大于0 小于1的随机小数(double)System.out.println(Math.random());}
运行结果:
0.34954795345479130.26140150112102790.195133086133228440.70292379592893570.36692989237008680.68171095601772440.207436448894262270.055490967319293260.35897737237637970.16557365319219486
Random rand =newRandom();System.out.println(rand.nextBoolean());//随机生成布尔型System.out.println(rand.nextDouble());//随机生成Double型
运行结果:
true0.36581163987123055