import java.util.Random;
import java.text.DecimalFormat;
public class Test {
public static void main(String[] args) throws Exception {
double max = 22.0;
double min = 11.0;
System.out.println(nextDouble(min - 1, max + 1));
}
public static double nextDouble(final double min, final double max) throws Exception {
//保留两位小数
DecimalFormat df = new DecimalFormat("#.00");
if (max < min) {
throw new Exception("min < max");
}
if (min == max) {
return min;
}
return Double.parseDouble(df.format(min + ((max - min) * new Random().nextDouble())));
}
}