1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.corpus;
15
16 import java.util.Random;
17
18 public class RandomUtil {
19
20
21
22
23
24
25
26
27 static public int gaussianAsPositiveInt(Random random, int average, int stdDeviation) {
28 if (average < 1) {
29 throw new IllegalArgumentException("The average must not be smaller than 1.");
30 }
31
32 if (stdDeviation < 1) {
33 throw new IllegalArgumentException("The stdDeviation must not be smaller than 1.");
34 }
35
36 double d = random.nextGaussian() * stdDeviation + average;
37 int result = 1;
38 if (d > 1.0) {
39 result = (int) Math.round(d);
40 }
41 return result;
42 }
43 }