// Path: core/src/java/main/org/uncommons/maths/number/NumberGenerator.java
// public interface NumberGenerator<T extends Number>
// {
//     /**
//      * @return The next value from the generator.
//      */
//     T nextValue();
// }


import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.uncommons.maths.number.NumberGenerator;
// ============================================================================
//   Copyright 2006-2012 Daniel W. Dyer
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
// ============================================================================
package org.uncommons.maths.demo;


/**
 * Encapsulates a probability distribution.  Provides both theoretical
 * values for the distribution as well as a way of randomly generating
 * values that follow this distribution.
 * @author Daniel Dyer
 */
abstract class ProbabilityDistribution
{
    protected abstract NumberGenerator<?> createValueGenerator(Random rng);

    public Map<Double, Double> generateValues(int count,
                                              Random rng)
    {
        Map<Double, Double> values = isDiscrete()
                                     ? generateDiscreteValues(count, rng)
                                     : generateContinuousValues(count, rng);

        double sum = 0;
        for (Double key : values.keySet())
        {
            Double value = values.get(key);
            values.put(key, value / count);
// Path: core/src/java/main/org/uncommons/maths/number/NumberGenerator.java
// public interface NumberGenerator<T extends Number>
// {
//     /**
//      * @return The next value from the generator.
//      */
//     T nextValue();
// }


// Path: demo/src/java/main/org/uncommons/maths/demo/ProbabilityDistribution.java
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.uncommons.maths.number.NumberGenerator;

// ============================================================================
//   Copyright 2006-2012 Daniel W. Dyer
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
// ============================================================================
package org.uncommons.maths.demo;


/**
 * Encapsulates a probability distribution.  Provides both theoretical
 * values for the distribution as well as a way of randomly generating
 * values that follow this distribution.
 * @author Daniel Dyer
 */
abstract class ProbabilityDistribution
{
    protected abstract NumberGenerator<?> createValueGenerator(Random rng);

    public Map<Double, Double> generateValues(int count,
                                              Random rng)
    {
        Map<Double, Double> values = isDiscrete()
                                     ? generateDiscreteValues(count, rng)
                                     : generateContinuousValues(count, rng);

        double sum = 0;
        for (Double key : values.keySet())
        {
            Double value = values.get(key);
            values.put(key, value / count);
            sum += value;