Java Code Examples for org.apache.commons.math.exception.util.LocalizedFormats#LOWER_BOUND_NOT_BELOW_UPPER_BOUND

The following examples show how to use org.apache.commons.math.exception.util.LocalizedFormats#LOWER_BOUND_NOT_BELOW_UPPER_BOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * <strong>Algorithm Description</strong>: scales the output of
 * Random.nextDouble(), but rejects 0 values (i.e., will generate another
 * random double if Random.nextDouble() returns 0). This is necessary to
 * provide a symmetric output interval (both endpoints excluded).
 * </p>
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return a uniformly distributed random value from the interval (lower,
 *         upper)
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public double nextUniform(double lower, double upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    final RandomGenerator generator = getRan();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (u <= 0.0) {
        u = generator.nextDouble();
    }

    return lower + u * (upper - lower);
}
 
Example 2
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * <strong>Algorithm Description</strong>: scales the output of
 * Random.nextDouble(), but rejects 0 values (i.e., will generate another
 * random double if Random.nextDouble() returns 0). This is necessary to
 * provide a symmetric output interval (both endpoints excluded).
 * </p>
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return a uniformly distributed random value from the interval (lower,
 *         upper)
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public double nextUniform(double lower, double upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    final RandomGenerator generator = getRan();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (u <= 0.0) {
        u = generator.nextDouble();
    }

    return lower + u * (upper - lower);
}
 
Example 3
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * <strong>Algorithm Description</strong>: scales the output of
 * Random.nextDouble(), but rejects 0 values (i.e., will generate another
 * random double if Random.nextDouble() returns 0). This is necessary to
 * provide a symmetric output interval (both endpoints excluded).
 * </p>
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return a uniformly distributed random value from the interval (lower,
 *         upper)
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public double nextUniform(double lower, double upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    final RandomGenerator generator = getRan();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (u <= 0.0) {
        u = generator.nextDouble();
    }

    return lower + u * (upper - lower);
}
 
Example 4
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * <strong>Algorithm Description</strong>: scales the output of
 * Random.nextDouble(), but rejects 0 values (i.e., will generate another
 * random double if Random.nextDouble() returns 0). This is necessary to
 * provide a symmetric output interval (both endpoints excluded).
 * </p>
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return a uniformly distributed random value from the interval (lower,
 *         upper)
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public double nextUniform(double lower, double upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    final RandomGenerator generator = getRan();

    // ensure nextDouble() isn't 0.0
    double u = generator.nextDouble();
    while (u <= 0.0) {
        u = generator.nextDouble();
    }

    return lower + u * (upper - lower);
}
 
Example 5
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random int value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public int nextInt(int lower, int upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    double r = getRan().nextDouble();
    return (int) ((r * upper) + ((1.0 - r) * lower) + r);
}
 
Example 6
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random long value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive. This algorithm uses
 * a secure random number generator.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public long nextSecureLong(long lower, long upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    SecureRandom sec = getSecRan();
    return lower + (long) (sec.nextDouble() * (upper - lower + 1));
}
 
Example 7
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random int value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive. This algorithm uses
 * a secure random number generator.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public int nextSecureInt(int lower, int upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    SecureRandom sec = getSecRan();
    return lower + (int) (sec.nextDouble() * (upper - lower + 1));
}
 
Example 8
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random long value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public long nextLong(long lower, long upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    double r = getRan().nextDouble();
    return (long) ((r * upper) + ((1.0 - r) * lower) + r);
}
 
Example 9
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random int value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public int nextInt(int lower, int upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    double r = getRan().nextDouble();
    return (int) ((r * upper) + ((1.0 - r) * lower) + r);
}
 
Example 10
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random long value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive. This algorithm uses
 * a secure random number generator.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public long nextSecureLong(long lower, long upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    SecureRandom sec = getSecRan();
    return lower + (long) (sec.nextDouble() * (upper - lower + 1));
}
 
Example 11
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random int value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive. This algorithm uses
 * a secure random number generator.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public int nextSecureInt(int lower, int upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    SecureRandom sec = getSecRan();
    return lower + (int) (sec.nextDouble() * (upper - lower + 1));
}
 
Example 12
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random long value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public long nextLong(long lower, long upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    double r = getRan().nextDouble();
    return (long) ((r * upper) + ((1.0 - r) * lower) + r);
}
 
Example 13
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random int value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public int nextInt(int lower, int upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    double r = getRan().nextDouble();
    return (int) ((r * upper) + ((1.0 - r) * lower) + r);
}
 
Example 14
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random long value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive. This algorithm uses
 * a secure random number generator.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public long nextSecureLong(long lower, long upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    SecureRandom sec = getSecRan();
    return lower + (long) (sec.nextDouble() * (upper - lower + 1));
}
 
Example 15
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random int value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive. This algorithm uses
 * a secure random number generator.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public int nextSecureInt(int lower, int upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    SecureRandom sec = getSecRan();
    return lower + (int) (sec.nextDouble() * (upper - lower + 1));
}
 
Example 16
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random long value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public long nextLong(long lower, long upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    double r = getRan().nextDouble();
    return (long) ((r * upper) + ((1.0 - r) * lower) + r);
}
 
Example 17
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random int value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public int nextInt(int lower, int upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    double r = getRan().nextDouble();
    return (int) ((r * upper) + ((1.0 - r) * lower) + r);
}
 
Example 18
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random long value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive. This algorithm uses
 * a secure random number generator.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public long nextSecureLong(long lower, long upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    SecureRandom sec = getSecRan();
    return lower + (long) (sec.nextDouble() * (upper - lower + 1));
}
 
Example 19
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random int value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive. This algorithm uses
 * a secure random number generator.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public int nextSecureInt(int lower, int upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    SecureRandom sec = getSecRan();
    return lower + (int) (sec.nextDouble() * (upper - lower + 1));
}
 
Example 20
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Generate a random long value uniformly distributed between
 * <code>lower</code> and <code>upper</code>, inclusive.
 *
 * @param lower
 *            the lower bound.
 * @param upper
 *            the upper bound.
 * @return the random integer.
 * @throws NumberIsTooLargeException if {@code lower >= upper}.
 */
public long nextLong(long lower, long upper) {
    if (lower >= upper) {
        throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                            lower, upper, false);
    }
    double r = getRan().nextDouble();
    return (long) ((r * upper) + ((1.0 - r) * lower) + r);
}