private static double getSliceQuantityinRange(double min, double max) {
double range = max - min;
double scaled = randomGenerator.nextDouble() * range;
double shifted = scaled + min;
return Double.valueOf((df.format(shifted)));
}
最小值和最大值将以百万计。这给出了一个范围之间的随机数。但我想要的是步数为10万(100000)的随机数。如何实现?
答案 0 :(得分:1)
以下是一个例子:
public static void main(String[] args) {
System.out.println(getSliceQuantityinRange(35000000, 52000000, 100000));
}
private static double getSliceQuantityinRange(double min, double max, double step) {
int range = (int)((max - min) / step);
double scaled = randomGenerator.nextInt(range) * step;
double shifted = scaled + min;
return Double.valueOf((df.format(shifted)));
}