有关数学运算的所有方法,参考 Math 库
随机数
Math.random() //[0..1)
Math.random()*100 //[0..100)
(int)(Math.random()*100+1) //[0..100]
小数的粗略比较
由于小数的计算不精确,存在微小误差,可以用如下方式,比较相对相等。
Math.random() //[0..1)
Math.random()*100 //[0..100)
(int)(Math.random()*100+1) //[0..100]
由于小数的计算不精确,存在微小误差,可以用如下方式,比较相对相等。