001 //Licensed to the Apache Software Foundation (ASF) under one 002 //or more contributor license agreements. See the NOTICE file 003 //distributed with this work for additional information 004 //regarding copyright ownership. The ASF licenses this file 005 //to you under the Apache License, Version 2.0 (the 006 //"License"); you may not use this file except in compliance 007 //with the License. You may obtain a copy of the License at 008 009 //http://www.apache.org/licenses/LICENSE-2.0 010 011 //Unless required by applicable law or agreed to in writing, 012 //software distributed under the License is distributed on an 013 //"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 014 //KIND, either express or implied. See the License for the 015 //specific language governing permissions and limitations 016 //under the License. 017 018 package org.apache.commons.math.random; 019 020 import org.apache.commons.math.stat.StatUtils; 021 022 import junit.framework.*; 023 024 public class UniformRandomGeneratorTest 025 extends TestCase { 026 027 public UniformRandomGeneratorTest(String name) { 028 super(name); 029 } 030 031 public void testMeanAndStandardDeviation() { 032 RandomGenerator rg = new JDKRandomGenerator(); 033 rg.setSeed(17399225432l); 034 UniformRandomGenerator generator = new UniformRandomGenerator(rg); 035 double[] sample = new double[10000]; 036 for (int i = 0; i < sample.length; ++i) { 037 sample[i] = generator.nextNormalizedDouble(); 038 } 039 assertEquals(0.0, StatUtils.mean(sample), 0.07); 040 assertEquals(1.0, StatUtils.variance(sample), 0.02); 041 } 042 043 044 public static Test suite() { 045 return new TestSuite(UniformRandomGeneratorTest.class); 046 } 047 048 }