2017-06-08 11 views
0

ちょっと、最小遅延、最大ms遅延、その他の計算を使ってランダムな遅延をコードしようとしています。このために私はいくつかの整数と長い値をクランプする必要があります。以下は、私がMathUtilに呼び出してクラスをコード化しようとしたクラスです。それはあなたが以下の見つけることができます使用している私はクランプメソッドをJavaで作成しようとしています

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または番号を返すことができるということです。遅延となる新しい番号を作成する必要があります。

+1

あなたの問題を理解することができません。あなたの質問を再フォーマットしてください。 –

+0

**編集**うまくいけば助けてください。 – JordanTheNoob

+0

'rand.nextInt((max-min)+ 1)+ min'の乱数を生成することを意味しますか? – 11thdimension

答えて

0

Clamp

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)); 
} 
関連する問題