1、 保留小数的随机数
Math.random()*(max-min)+min
double d = Math.random() * 2 + 6;
DecimalFormat df = new DecimalFormat("0.0000");
String format = df.format(d);
System.out.println(format);
生成 6 - 8 之间随机数 并保留4位小数。
代码中 2 代表 最小= 0 最大 为 2