001package squidpony.squidmath;
002
003/**
004 * An IDistribution that produces results between 0.0 inclusive and 1.0 exclusive, but is much more likely to produce
005 * results near 0.0 or 1.0, further from 0.5.
006 * <br>
007 * Created by Tommy Ettinger on 11/23/2019.
008 */
009public class BathtubDistribution extends IDistribution.SimpleDistribution implements IDistribution {
010    public static final BathtubDistribution instance = new BathtubDistribution();
011    /**
012     * Gets a double between {@link #getLowerBound()} and {@link #getUpperBound()} that obeys this distribution.
013     *
014     * @param rng an IRNG, such as {@link RNG} or {@link GWTRNG}, that this will get one or more random numbers from
015     * @return a double within the range of {@link #getLowerBound()} and {@link #getUpperBound()}
016     */
017    @Override
018    public double nextDouble(IRNG rng) {
019        double d = (rng.nextDouble() - 0.5) * 2.0;
020        d = d * d * d + 1.0;
021        return d - (int)d;
022    }
023}