All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.robertboothby.djenni.distribution.simple.SimpleRandomIntegerDistribution Maven / Gradle / Ivy

Go to download

This module holds the core components of the Djenni data generator framework. By itself it provides most of the components to create an efficient end to end data generation framework for a specific domain. It contains the core SupplierBuilder interfaces, implementations for the core Java data types and useful test components. It is intended to be used in conjunction with the source-generator module that will speed up delivery of domain specific data generation and also with common domain modules (TBD) that deliver standard generators for common frameworks such as JAXB.

There is a newer version: 0.2.0
Show newest version
package com.robertboothby.djenni.distribution.simple;

import com.robertboothby.djenni.distribution.Distribution;
import org.hamcrest.Description;

/**
 * This class holds the current set of simple integer distributions. All the distributions are based on those found in
 * {@link com.robertboothby.djenni.distribution.simple.SimpleRandomBigIntegerDistribution}.
 * @author robertboothby
 */
public class SimpleRandomIntegerDistribution implements Distribution {

    private final SimpleRandomDoubleDistribution underlyingDistribution;

    /**
     * This distribution generates Integers following the distribution defined in {@link SimpleRandomLongDistribution#UNIFORM}.
     */
    public static final SimpleRandomIntegerDistribution UNIFORM =
            new SimpleRandomIntegerDistribution(SimpleRandomDoubleDistribution.UNIFORM);

    /**
     * This distribution generates Integers following the distribution defined in {@link SimpleRandomLongDistribution#NORMAL}.
     */
    public static final SimpleRandomIntegerDistribution NORMAL =
            new SimpleRandomIntegerDistribution(SimpleRandomDoubleDistribution.NORMAL);

    /**
     * This distribution generates Integers following the distribution defined in {@link SimpleRandomLongDistribution#LEFT_NORMAL}.
     */
    public static final SimpleRandomIntegerDistribution LEFT_NORMAL =
            new SimpleRandomIntegerDistribution(SimpleRandomDoubleDistribution.LEFT_NORMAL);

    /**
     * This distribution generates Integers following the distribution defined in {@link SimpleRandomLongDistribution#RIGHT_NORMAL}.
     */
    public static final SimpleRandomIntegerDistribution RIGHT_NORMAL =
            new SimpleRandomIntegerDistribution(SimpleRandomDoubleDistribution.RIGHT_NORMAL);

    /**
     * This distribution generates Integers following the distribution defined in {@link SimpleRandomLongDistribution#INVERTED_NORMAL}.
     */
    public static final SimpleRandomIntegerDistribution INVERTED_NORMAL =
            new SimpleRandomIntegerDistribution(SimpleRandomDoubleDistribution.INVERTED_NORMAL);

    /**
     * This distribution generates Integers following the distribution defined in {@link SimpleRandomLongDistribution#LEFT_INVERTED_NORMAL}.
     */
    public static final SimpleRandomIntegerDistribution LEFT_INVERTED_NORMAL =
            new SimpleRandomIntegerDistribution(SimpleRandomDoubleDistribution.LEFT_INVERTED_NORMAL);

    /**
     * This distribution generates Integers following the distribution defined in {@link SimpleRandomLongDistribution#RIGHT_INVERTED_NORMAL}.
     */
    public static final SimpleRandomIntegerDistribution RIGHT_INVERTED_NORMAL =
            new SimpleRandomIntegerDistribution(SimpleRandomDoubleDistribution.RIGHT_INVERTED_NORMAL);

    public SimpleRandomIntegerDistribution(SimpleRandomDoubleDistribution underlyingDistribution) {
        this.underlyingDistribution = underlyingDistribution;
    }

    public Integer generate(Integer bound) {
        return (int) Math.floor(underlyingDistribution.nextDouble() * bound);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy