public static void main(String[] args) {
test1(3,16,2);
}
/**
* 生成两个整数之间的随机小数
* @param min 最小值
* @param max 最大值
* @param num 保留小数点位数
*/
public static void test1(int min, int max,int num){
Runnable a = () -> {
System.out.println(new BigDecimal(min+Math.random()*(max-min)).setScale(num,BigDecimal.ROUND_HALF_UP));
};
int i = 0;
while (i<10){
new Thread(a).start();
i++;
}
}
输出结果:
12.32
7.15
10.59
6.48
13.73
5.75
14.95
6.30
3.04
14.89
Process finished with exit code 0