220 |
|
} |
221 |
|
|
222 |
|
// IllegalArgumentException messages |
223 |
< |
static final String BadBound = "bound must be positive"; |
224 |
< |
static final String BadRange = "bound must be greater than origin"; |
225 |
< |
static final String BadSize = "size must be non-negative"; |
223 |
> |
static final String BAD_BOUND = "bound must be positive"; |
224 |
> |
static final String BAD_RANGE = "bound must be greater than origin"; |
225 |
> |
static final String BAD_SIZE = "size must be non-negative"; |
226 |
|
|
227 |
|
/** |
228 |
|
* The form of nextLong used by LongStream Spliterators. If |
320 |
|
*/ |
321 |
|
public int nextInt(int bound) { |
322 |
|
if (bound <= 0) |
323 |
< |
throw new IllegalArgumentException(BadBound); |
323 |
> |
throw new IllegalArgumentException(BAD_BOUND); |
324 |
|
int r = mix32(nextSeed()); |
325 |
|
int m = bound - 1; |
326 |
|
if ((bound & m) == 0) // power of two |
347 |
|
*/ |
348 |
|
public int nextInt(int origin, int bound) { |
349 |
|
if (origin >= bound) |
350 |
< |
throw new IllegalArgumentException(BadRange); |
350 |
> |
throw new IllegalArgumentException(BAD_RANGE); |
351 |
|
return internalNextInt(origin, bound); |
352 |
|
} |
353 |
|
|
371 |
|
*/ |
372 |
|
public long nextLong(long bound) { |
373 |
|
if (bound <= 0) |
374 |
< |
throw new IllegalArgumentException(BadBound); |
374 |
> |
throw new IllegalArgumentException(BAD_BOUND); |
375 |
|
long r = mix64(nextSeed()); |
376 |
|
long m = bound - 1; |
377 |
|
if ((bound & m) == 0L) // power of two |
398 |
|
*/ |
399 |
|
public long nextLong(long origin, long bound) { |
400 |
|
if (origin >= bound) |
401 |
< |
throw new IllegalArgumentException(BadRange); |
401 |
> |
throw new IllegalArgumentException(BAD_RANGE); |
402 |
|
return internalNextLong(origin, bound); |
403 |
|
} |
404 |
|
|
424 |
|
*/ |
425 |
|
public double nextDouble(double bound) { |
426 |
|
if (!(bound > 0.0)) |
427 |
< |
throw new IllegalArgumentException(BadBound); |
427 |
> |
throw new IllegalArgumentException(BAD_BOUND); |
428 |
|
double result = (mix64(nextSeed()) >>> 11) * DOUBLE_UNIT * bound; |
429 |
|
return (result < bound) ? result : // correct for rounding |
430 |
|
Double.longBitsToDouble(Double.doubleToLongBits(bound) - 1); |
443 |
|
*/ |
444 |
|
public double nextDouble(double origin, double bound) { |
445 |
|
if (!(origin < bound)) |
446 |
< |
throw new IllegalArgumentException(BadRange); |
446 |
> |
throw new IllegalArgumentException(BAD_RANGE); |
447 |
|
return internalNextDouble(origin, bound); |
448 |
|
} |
449 |
|
|
500 |
|
*/ |
501 |
|
public IntStream ints(long streamSize) { |
502 |
|
if (streamSize < 0L) |
503 |
< |
throw new IllegalArgumentException(BadSize); |
503 |
> |
throw new IllegalArgumentException(BAD_SIZE); |
504 |
|
return StreamSupport.intStream |
505 |
|
(new RandomIntsSpliterator |
506 |
|
(0L, streamSize, Integer.MAX_VALUE, 0), |
542 |
|
public IntStream ints(long streamSize, int randomNumberOrigin, |
543 |
|
int randomNumberBound) { |
544 |
|
if (streamSize < 0L) |
545 |
< |
throw new IllegalArgumentException(BadSize); |
545 |
> |
throw new IllegalArgumentException(BAD_SIZE); |
546 |
|
if (randomNumberOrigin >= randomNumberBound) |
547 |
< |
throw new IllegalArgumentException(BadRange); |
547 |
> |
throw new IllegalArgumentException(BAD_RANGE); |
548 |
|
return StreamSupport.intStream |
549 |
|
(new RandomIntsSpliterator |
550 |
|
(0L, streamSize, randomNumberOrigin, randomNumberBound), |
569 |
|
*/ |
570 |
|
public IntStream ints(int randomNumberOrigin, int randomNumberBound) { |
571 |
|
if (randomNumberOrigin >= randomNumberBound) |
572 |
< |
throw new IllegalArgumentException(BadRange); |
572 |
> |
throw new IllegalArgumentException(BAD_RANGE); |
573 |
|
return StreamSupport.intStream |
574 |
|
(new RandomIntsSpliterator |
575 |
|
(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), |
588 |
|
*/ |
589 |
|
public LongStream longs(long streamSize) { |
590 |
|
if (streamSize < 0L) |
591 |
< |
throw new IllegalArgumentException(BadSize); |
591 |
> |
throw new IllegalArgumentException(BAD_SIZE); |
592 |
|
return StreamSupport.longStream |
593 |
|
(new RandomLongsSpliterator |
594 |
|
(0L, streamSize, Long.MAX_VALUE, 0L), |
630 |
|
public LongStream longs(long streamSize, long randomNumberOrigin, |
631 |
|
long randomNumberBound) { |
632 |
|
if (streamSize < 0L) |
633 |
< |
throw new IllegalArgumentException(BadSize); |
633 |
> |
throw new IllegalArgumentException(BAD_SIZE); |
634 |
|
if (randomNumberOrigin >= randomNumberBound) |
635 |
< |
throw new IllegalArgumentException(BadRange); |
635 |
> |
throw new IllegalArgumentException(BAD_RANGE); |
636 |
|
return StreamSupport.longStream |
637 |
|
(new RandomLongsSpliterator |
638 |
|
(0L, streamSize, randomNumberOrigin, randomNumberBound), |
657 |
|
*/ |
658 |
|
public LongStream longs(long randomNumberOrigin, long randomNumberBound) { |
659 |
|
if (randomNumberOrigin >= randomNumberBound) |
660 |
< |
throw new IllegalArgumentException(BadRange); |
660 |
> |
throw new IllegalArgumentException(BAD_RANGE); |
661 |
|
return StreamSupport.longStream |
662 |
|
(new RandomLongsSpliterator |
663 |
|
(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), |
677 |
|
*/ |
678 |
|
public DoubleStream doubles(long streamSize) { |
679 |
|
if (streamSize < 0L) |
680 |
< |
throw new IllegalArgumentException(BadSize); |
680 |
> |
throw new IllegalArgumentException(BAD_SIZE); |
681 |
|
return StreamSupport.doubleStream |
682 |
|
(new RandomDoublesSpliterator |
683 |
|
(0L, streamSize, Double.MAX_VALUE, 0.0), |
721 |
|
public DoubleStream doubles(long streamSize, double randomNumberOrigin, |
722 |
|
double randomNumberBound) { |
723 |
|
if (streamSize < 0L) |
724 |
< |
throw new IllegalArgumentException(BadSize); |
724 |
> |
throw new IllegalArgumentException(BAD_SIZE); |
725 |
|
if (!(randomNumberOrigin < randomNumberBound)) |
726 |
< |
throw new IllegalArgumentException(BadRange); |
726 |
> |
throw new IllegalArgumentException(BAD_RANGE); |
727 |
|
return StreamSupport.doubleStream |
728 |
|
(new RandomDoublesSpliterator |
729 |
|
(0L, streamSize, randomNumberOrigin, randomNumberBound), |
748 |
|
*/ |
749 |
|
public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) { |
750 |
|
if (!(randomNumberOrigin < randomNumberBound)) |
751 |
< |
throw new IllegalArgumentException(BadRange); |
751 |
> |
throw new IllegalArgumentException(BAD_RANGE); |
752 |
|
return StreamSupport.doubleStream |
753 |
|
(new RandomDoublesSpliterator |
754 |
|
(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound), |