1、double value = Math.random();
默认数据类型是double
默认范围 [ 0.0, 1.0 )
2、获得区间 [ a,b ] 范围内的随机数:
(int) (Math.random() * (b - a + 1) + a);
eg:获得一个两位数[10,99]
(int)(Math.random() * 90 + 10);
1、double value = Math.random();
默认数据类型是double
默认范围 [ 0.0, 1.0 )
2、获得区间 [ a,b ] 范围内的随机数:
(int) (Math.random() * (b - a + 1) + a);
eg:获得一个两位数[10,99]
(int)(Math.random() * 90 + 10);