-1

嘿,所以我正在尝试使用最小毫秒延迟、最大毫秒延迟和其他一些计算来编写随机延迟。为此,我需要钳制一些整数和一个长整数。下面是一个我调用 MathUtil 来尝试编写 Clamp 的类。

public static long clamp(long delayPreClamp, int min, int max) {
    return 90;
}

您可以在下面找到它使用的数字:

double deviation = 22;
                    double mean = 90;
                    int min = 43;
                    int max = 198;
                    Random r = new Random();
                    double randGauss = (r.nextGaussian() * deviation);
                    long delayPreClamp = Math.round(randGauss + mean);
                    long delay = (long) MathUtil.clamp(delayPreClamp, min, max);

我的问题是,在第一个提到的代码中,我只能返回 min、max、delayPreClamp 或一个数字。我需要它来创建一个新号码,这将是延迟。

4

1 回答 1

1

夹钳

public static long clamp(long delayPreClamp, int min, int max) {
    // v = delayPreClamp
    // if v < min, returns the greater between min and v, thus min
    // if v > max, returns the greater between min and max, thus max
    // if v is between min and max, returns the greater between min and v, thus v
    return Math.max(min, Math.min(delayPreclamp, max));
}
于 2017-06-13T18:13:03.817 回答