产生随机数random

Math.random()方法是一个可以产生[0.0,1.0]区间内的一个双精度浮点数的方法

产生一个100以内的整数:
int x=(int)(Math.random()*100);

产生一个1-50之间的随机数:
int x=1+(int)(Math.random()*50)

 

posted @ 2016-09-08 23:40  乱世_独自美  阅读(94)  评论(0)    收藏  举报