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

com.robertboothby.djenni.distribution.simple.SimpleRandomLongDistribution 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;

/**
 *
 * @author robertboothby
 */
public class SimpleRandomLongDistribution implements Distribution {

    private final SimpleRandomDoubleDistribution underlyingDistribution;

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

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

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

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

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

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

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

    /**
     * Construct an instance of the distribution using the underlying distribution.
     * @param underlyingDistribution The underlying distribution to use.
     */
    public SimpleRandomLongDistribution(SimpleRandomDoubleDistribution underlyingDistribution) {
        this.underlyingDistribution = underlyingDistribution;
    }

    @Override
    public Long generate(Long bound) {
        return (long) Math.floor(underlyingDistribution.nextDouble() * bound);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy