src/share/classes/java/util/Random.java

Print this page




 857      *         each with the given origin (inclusive) and bound (exclusive)
 858      * @throws IllegalArgumentException if {@code randomNumberOrigin}
 859      *         is greater than or equal to {@code randomNumberBound}
 860      * @since 1.8
 861      */
 862     public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
 863         if (randomNumberOrigin >= randomNumberBound)
 864             throw new IllegalArgumentException(BadRange);
 865         return StreamSupport.longStream
 866                 (new RandomLongsSpliterator
 867                          (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
 868                  false);
 869     }
 870 
 871     /**
 872      * Returns a stream producing the given {@code streamSize} number of
 873      * pseudorandom {@code double} values, each between zero
 874      * (inclusive) and one (exclusive).
 875      *
 876      * <p>A pseudorandom {@code double} value is generated as if it's the result
 877      * of calling the method {@link #nextDouble()}}.
 878      *
 879      * @param streamSize the number of values to generate
 880      * @return a stream of {@code double} values
 881      * @throws IllegalArgumentException if {@code streamSize} is
 882      *         less than zero
 883      * @since 1.8
 884      */
 885     public DoubleStream doubles(long streamSize) {
 886         if (streamSize < 0L)
 887             throw new IllegalArgumentException(BadSize);
 888         return StreamSupport.doubleStream
 889                 (new RandomDoublesSpliterator
 890                          (this, 0L, streamSize, Double.MAX_VALUE, 0.0),
 891                  false);
 892     }
 893 
 894     /**
 895      * Returns an effectively unlimited stream of pseudorandom {@code
 896      * double} values, each between zero (inclusive) and one
 897      * (exclusive).
 898      *
 899      * <p>A pseudorandom {@code double} value is generated as if it's the result
 900      * of calling the method {@link #nextDouble()}}.
 901      *
 902      * @implNote This method is implemented to be equivalent to {@code
 903      * doubles(Long.MAX_VALUE)}.
 904      *
 905      * @return a stream of pseudorandom {@code double} values
 906      * @since 1.8
 907      */
 908     public DoubleStream doubles() {
 909         return StreamSupport.doubleStream
 910                 (new RandomDoublesSpliterator
 911                          (this, 0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0),
 912                  false);
 913     }
 914 
 915     /**
 916      * Returns a stream producing the given {@code streamSize} number of
 917      * pseudorandom {@code double} values, each conforming to the given origin
 918      * (inclusive) and bound (exclusive).
 919      *
 920      * <p>A pseudorandom {@code double} value is generated as if it's the result




 857      *         each with the given origin (inclusive) and bound (exclusive)
 858      * @throws IllegalArgumentException if {@code randomNumberOrigin}
 859      *         is greater than or equal to {@code randomNumberBound}
 860      * @since 1.8
 861      */
 862     public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
 863         if (randomNumberOrigin >= randomNumberBound)
 864             throw new IllegalArgumentException(BadRange);
 865         return StreamSupport.longStream
 866                 (new RandomLongsSpliterator
 867                          (this, 0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
 868                  false);
 869     }
 870 
 871     /**
 872      * Returns a stream producing the given {@code streamSize} number of
 873      * pseudorandom {@code double} values, each between zero
 874      * (inclusive) and one (exclusive).
 875      *
 876      * <p>A pseudorandom {@code double} value is generated as if it's the result
 877      * of calling the method {@link #nextDouble()}.
 878      *
 879      * @param streamSize the number of values to generate
 880      * @return a stream of {@code double} values
 881      * @throws IllegalArgumentException if {@code streamSize} is
 882      *         less than zero
 883      * @since 1.8
 884      */
 885     public DoubleStream doubles(long streamSize) {
 886         if (streamSize < 0L)
 887             throw new IllegalArgumentException(BadSize);
 888         return StreamSupport.doubleStream
 889                 (new RandomDoublesSpliterator
 890                          (this, 0L, streamSize, Double.MAX_VALUE, 0.0),
 891                  false);
 892     }
 893 
 894     /**
 895      * Returns an effectively unlimited stream of pseudorandom {@code
 896      * double} values, each between zero (inclusive) and one
 897      * (exclusive).
 898      *
 899      * <p>A pseudorandom {@code double} value is generated as if it's the result
 900      * of calling the method {@link #nextDouble()}.
 901      *
 902      * @implNote This method is implemented to be equivalent to {@code
 903      * doubles(Long.MAX_VALUE)}.
 904      *
 905      * @return a stream of pseudorandom {@code double} values
 906      * @since 1.8
 907      */
 908     public DoubleStream doubles() {
 909         return StreamSupport.doubleStream
 910                 (new RandomDoublesSpliterator
 911                          (this, 0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0),
 912                  false);
 913     }
 914 
 915     /**
 916      * Returns a stream producing the given {@code streamSize} number of
 917      * pseudorandom {@code double} values, each conforming to the given origin
 918      * (inclusive) and bound (exclusive).
 919      *
 920      * <p>A pseudorandom {@code double} value is generated as if it's the result