本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND属性的具体用法?Java LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND怎么用?Java LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.exception.util.LocalizedFormats
的用法示例。
在下文中一共展示了LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nextLong
/** {@inheritDoc} */
public long nextLong(final long lower, final long upper) throws NumberIsTooLargeException {
if (lower >= upper) {
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
lower, upper, false);
}
final long max = (upper - lower) + 1;
if (max <= 0) {
// the range is too wide to fit in a positive long (larger than 2^63); as it covers
// more than half the long range, we use directly a simple rejection method
final RandomGenerator rng = getRandomGenerator();
while (true) {
final long r = rng.nextLong();
if (r >= lower && r <= upper) {
return r;
}
}
} else if (max < Integer.MAX_VALUE){
// we can shift the range and generate directly a positive int
return lower + getRandomGenerator().nextInt((int) max);
} else {
// we can shift the range and generate directly a positive long
return lower + nextLong(getRandomGenerator(), max);
}
}
示例2: nextSecureLong
/** {@inheritDoc} */
public long nextSecureLong(final long lower, final long upper) throws NumberIsTooLargeException {
if (lower >= upper) {
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
lower, upper, false);
}
final RandomGenerator rng = getSecRan();
final long max = (upper - lower) + 1;
if (max <= 0) {
// the range is too wide to fit in a positive long (larger than 2^63); as it covers
// more than half the long range, we use directly a simple rejection method
while (true) {
final long r = rng.nextLong();
if (r >= lower && r <= upper) {
return r;
}
}
} else if (max < Integer.MAX_VALUE){
// we can shift the range and generate directly a positive int
return lower + rng.nextInt((int) max);
} else {
// we can shift the range and generate directly a positive long
return lower + nextLong(rng, max);
}
}
示例3: UniformRealDistribution
/**
* Creates a uniform distribution.
*
* @param rng Random number generator.
* @param lower Lower bound of this distribution (inclusive).
* @param upper Upper bound of this distribution (exclusive).
* @throws NumberIsTooLargeException if {@code lower >= upper}.
* @since 3.1
*/
public UniformRealDistribution(RandomGenerator rng,
double lower,
double upper)
throws NumberIsTooLargeException {
super(rng);
if (lower >= upper) {
throw new NumberIsTooLargeException(
LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
lower, upper, false);
}
this.lower = lower;
this.upper = upper;
}
示例4: TriangularDistribution
/**
* Creates a triangular distribution.
*
* @param rng Random number generator.
* @param a Lower limit of this distribution (inclusive).
* @param b Upper limit of this distribution (inclusive).
* @param c Mode of this distribution.
* @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}.
* @throws NumberIsTooSmallException if {@code c < a}.
* @since 3.1
*/
public TriangularDistribution(RandomGenerator rng,
double a,
double c,
double b)
throws NumberIsTooLargeException, NumberIsTooSmallException {
super(rng);
if (a >= b) {
throw new NumberIsTooLargeException(
LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
a, b, false);
}
if (c < a) {
throw new NumberIsTooSmallException(
LocalizedFormats.NUMBER_TOO_SMALL, c, a, true);
}
if (c > b) {
throw new NumberIsTooLargeException(
LocalizedFormats.NUMBER_TOO_LARGE, c, b, true);
}
this.a = a;
this.c = c;
this.b = b;
solverAbsoluteAccuracy = FastMath.max(FastMath.ulp(a), FastMath.ulp(b));
}
示例5: UniformIntegerDistribution
/**
* Creates a new uniform integer distribution using the given lower and
* upper bounds (both inclusive).
*
* @param rng Random number generator.
* @param lower Lower bound (inclusive) of this distribution.
* @param upper Upper bound (inclusive) of this distribution.
* @throws NumberIsTooLargeException if {@code lower > upper}.
* @since 3.1
*/
public UniformIntegerDistribution(RandomGenerator rng,
int lower,
int upper)
throws NumberIsTooLargeException {
super(rng);
if (lower > upper) {
throw new NumberIsTooLargeException(
LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
lower, upper, true);
}
this.lower = lower;
this.upper = upper;
}
示例6: checkParameters
/**
* Verifies that (lower, upper) is a valid non-empty interval and confidence
* is strictly between 0 and 1.
*
* @param lower lower endpoint
* @param upper upper endpoint
* @param confidence confidence level
*/
private void checkParameters(double lower, double upper, double confidence) {
if (lower >= upper) {
throw new MathIllegalArgumentException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper);
}
if (confidence <= 0 || confidence >= 1) {
throw new MathIllegalArgumentException(LocalizedFormats.OUT_OF_BOUNDS_CONFIDENCE_LEVEL, confidence, 0, 1);
}
}
示例7: nextUniform
/**
* {@inheritDoc}
*
* <p>
* <strong>Algorithm Description</strong>: if the lower bound is excluded,
* 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>
*
* @throws NumberIsTooLargeException if {@code lower >= upper}
* @throws NotFiniteNumberException if one of the bounds is infinite
* @throws NotANumberException if one of the bounds is NaN
*/
public double nextUniform(double lower, double upper, boolean lowerInclusive)
throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException {
if (lower >= upper) {
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
lower, upper, false);
}
if (Double.isInfinite(lower)) {
throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, lower);
}
if (Double.isInfinite(upper)) {
throw new NotFiniteNumberException(LocalizedFormats.INFINITE_BOUND, upper);
}
if (Double.isNaN(lower) || Double.isNaN(upper)) {
throw new NotANumberException();
}
final RandomGenerator generator = getRandomGenerator();
// ensure nextDouble() isn't 0.0
double u = generator.nextDouble();
while (!lowerInclusive && u <= 0.0) {
u = generator.nextDouble();
}
return u * upper + (1.0 - u) * lower;
}