Merge pull request #425 from shenqioa/master

RandomUtils : comment error
This commit is contained in:
Bruno P. Kinoshita 2019-08-25 10:51:39 +12:00 committed by GitHub
commit 094ee7ecbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View File

@ -166,23 +166,23 @@ public class RandomUtils {
* *
* @param startInclusive * @param startInclusive
* the smallest value that can be returned, must be non-negative * the smallest value that can be returned, must be non-negative
* @param endInclusive * @param endExclusive
* the upper bound (included) * the upper bound (not included)
* @throws IllegalArgumentException * @throws IllegalArgumentException
* if {@code startInclusive > endInclusive} or if * if {@code startInclusive > endExclusive} or if
* {@code startInclusive} is negative * {@code startInclusive} is negative
* @return the random double * @return the random double
*/ */
public static double nextDouble(final double startInclusive, final double endInclusive) { public static double nextDouble(final double startInclusive, final double endExclusive) {
Validate.isTrue(endInclusive >= startInclusive, Validate.isTrue(endExclusive >= startInclusive,
"Start value must be smaller or equal to end value."); "Start value must be smaller or equal to end value.");
Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative."); Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative.");
if (startInclusive == endInclusive) { if (startInclusive == endExclusive) {
return startInclusive; return startInclusive;
} }
return startInclusive + ((endInclusive - startInclusive) * RANDOM.nextDouble()); return startInclusive + ((endExclusive - startInclusive) * RANDOM.nextDouble());
} }
/** /**
@ -203,30 +203,30 @@ public class RandomUtils {
* *
* @param startInclusive * @param startInclusive
* the smallest value that can be returned, must be non-negative * the smallest value that can be returned, must be non-negative
* @param endInclusive * @param endExclusive
* the upper bound (included) * the upper bound (not included)
* @throws IllegalArgumentException * @throws IllegalArgumentException
* if {@code startInclusive > endInclusive} or if * if {@code startInclusive > endExclusive} or if
* {@code startInclusive} is negative * {@code startInclusive} is negative
* @return the random float * @return the random float
*/ */
public static float nextFloat(final float startInclusive, final float endInclusive) { public static float nextFloat(final float startInclusive, final float endExclusive) {
Validate.isTrue(endInclusive >= startInclusive, Validate.isTrue(endExclusive >= startInclusive,
"Start value must be smaller or equal to end value."); "Start value must be smaller or equal to end value.");
Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative."); Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative.");
if (startInclusive == endInclusive) { if (startInclusive == endExclusive) {
return startInclusive; return startInclusive;
} }
return startInclusive + ((endInclusive - startInclusive) * RANDOM.nextFloat()); return startInclusive + ((endExclusive - startInclusive) * RANDOM.nextFloat());
} }
/** /**
* <p> Returns a random float within 0 - Float.MAX_VALUE </p> * <p> Returns a random float within 0 - Float.MAX_VALUE </p>
* *
* @return the random float * @return the random float
* @see #nextFloat() * @see #nextFloat(float, float)
* @since 3.5 * @since 3.5
*/ */
public static float nextFloat() { public static float nextFloat() {

View File

@ -137,7 +137,7 @@ public class RandomUtilsTest {
} }
/** /**
* Tests next double range, random result. * Tests next int range, random result.
*/ */
@Test @Test
public void testNextIntRandomResult() { public void testNextIntRandomResult() {