1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.math.random;
19
20 import org.apache.commons.math.stat.StatUtils;
21
22 import junit.framework.*;
23
24 public class UniformRandomGeneratorTest
25 extends TestCase {
26
27 public UniformRandomGeneratorTest(String name) {
28 super(name);
29 }
30
31 public void testMeanAndStandardDeviation() {
32 RandomGenerator rg = new JDKRandomGenerator();
33 rg.setSeed(17399225432l);
34 UniformRandomGenerator generator = new UniformRandomGenerator(rg);
35 double[] sample = new double[10000];
36 for (int i = 0; i < sample.length; ++i) {
37 sample[i] = generator.nextNormalizedDouble();
38 }
39 assertEquals(0.0, StatUtils.mean(sample), 0.07);
40 assertEquals(1.0, StatUtils.variance(sample), 0.02);
41 }
42
43
44 public static Test suite() {
45 return new TestSuite(UniformRandomGeneratorTest.class);
46 }
47
48 }