newrandom/AbstractSpliteratorRng.java
author briangoetz
Thu, 23 May 2019 16:45:56 -0400
branchbriangoetz-test-branch
changeset 57369 6d87e9f7a1ec
permissions -rwxr-xr-x
Initial comment in newrandom/
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57369
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
     1
/*
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
     3
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
     4
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
     5
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
     6
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
     7
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
     8
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
     9
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    10
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    11
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    12
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    13
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    14
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    15
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    16
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    17
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    18
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    19
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    20
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    21
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    22
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    23
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    24
 */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    25
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    26
// package java.util;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    27
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    28
import java.util.Spliterator;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    29
import java.util.function.Consumer;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    30
import java.util.function.IntConsumer;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    31
import java.util.function.LongConsumer;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    32
import java.util.function.DoubleConsumer;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    33
import java.util.stream.StreamSupport;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    34
import java.util.stream.IntStream;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    35
import java.util.stream.LongStream;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    36
import java.util.stream.DoubleStream;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    37
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    38
/**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    39
 * This class overrides the stream-producing methods (such as {@code ints()})
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    40
 * in class {@code AbstractRng} to provide {@code Spliterator}-based
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    41
 * implmentations that support potentially parallel execution.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    42
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    43
 * To implement a pseudorandom number generator, the programmer needs
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    44
 * only to extend this class and provide implementations for the methods
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    45
 * {@code nextInt()}, {@code nextLong()}, {@code makeIntsSpliterator},
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    46
 * {@code makeLongsSpliterator}, and {@code makeDoublesSpliterator}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    47
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    48
 * This class is not public; it provides shared code to the public
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    49
 * classes {@code AbstractSplittableRng}, {@code AbstractSharedRng},
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    50
 * and {@code AbstractArbitrarilyJumpableRng}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    51
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    52
 * @author  Guy Steele
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    53
 * @author  Doug Lea
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    54
 * @since   1.9
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    55
 */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    56
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    57
abstract class AbstractSpliteratorRng implements Rng {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    58
    /*
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    59
     * Implementation Overview.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    60
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    61
     * This class provides most of the "user API" methods needed to
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    62
     * satisfy the interface java.util.Rng.  An implementation of this
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    63
     * interface need only extend this class and provide implementations
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    64
     * of six methods: nextInt, nextLong, and nextDouble (the versions
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    65
     * that take no arguments) and makeIntsSpliterator,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    66
     * makeLongsSpliterator, and makeDoublesSpliterator.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    67
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    68
     * File organization: First the non-public abstract methods needed
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    69
     * to create spliterators, then the main public methods.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    70
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    71
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    72
    abstract Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    73
    abstract Spliterator.OfLong makeLongsSpliterator(long index, long fence, long origin, long bound);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    74
    abstract Spliterator.OfDouble makeDoublesSpliterator(long index, long fence, double origin, double bound);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    75
	
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    76
    /* ---------------- public methods ---------------- */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    77
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    78
    // stream methods, coded in a way intended to better isolate for
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    79
    // maintenance purposes the small differences across forms.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    80
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    81
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    82
     * Returns a stream producing the given {@code streamSize} number
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    83
     * of pseudorandom {@code int} values from this generator and/or
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    84
     * one split from it.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    85
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    86
     * @param streamSize the number of values to generate
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    87
     * @return a stream of pseudorandom {@code int} values
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    88
     * @throws IllegalArgumentException if {@code streamSize} is
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    89
     *         less than zero
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    90
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    91
    public IntStream ints(long streamSize) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    92
	RngSupport.checkStreamSize(streamSize);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    93
        return StreamSupport.intStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    94
            (makeIntsSpliterator(0L, streamSize, Integer.MAX_VALUE, 0),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    95
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    96
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    97
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    98
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    99
     * Returns an effectively unlimited stream of pseudorandomly chosen
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   100
     * {@code int} values.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   101
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   102
     * @implNote The implementation of this method is effectively
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   103
     * equivalent to {@code ints(Long.MAX_VALUE)}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   104
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   105
     * @return a stream of pseudorandomly chosen {@code int} values
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   106
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   107
    
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   108
    public IntStream ints() {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   109
        return StreamSupport.intStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   110
            (makeIntsSpliterator(0L, Long.MAX_VALUE, Integer.MAX_VALUE, 0),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   111
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   112
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   113
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   114
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   115
     * Returns a stream producing the given {@code streamSize} number
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   116
     * of pseudorandom {@code int} values from this generator and/or one split
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   117
     * from it; each value conforms to the given origin (inclusive) and bound
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   118
     * (exclusive).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   119
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   120
     * @param streamSize the number of values to generate
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   121
     * @param randomNumberOrigin the origin (inclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   122
     * @param randomNumberBound the bound (exclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   123
     * @return a stream of pseudorandom {@code int} values,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   124
     *         each with the given origin (inclusive) and bound (exclusive)
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   125
     * @throws IllegalArgumentException if {@code streamSize} is
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   126
     *         less than zero, or {@code randomNumberOrigin}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   127
     *         is greater than or equal to {@code randomNumberBound}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   128
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   129
    public IntStream ints(long streamSize, int randomNumberOrigin,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   130
			   int randomNumberBound) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   131
	RngSupport.checkStreamSize(streamSize);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   132
	RngSupport.checkRange(randomNumberOrigin, randomNumberBound);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   133
        return StreamSupport.intStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   134
            (makeIntsSpliterator(0L, streamSize, randomNumberOrigin, randomNumberBound),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   135
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   136
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   137
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   138
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   139
     * Returns an effectively unlimited stream of pseudorandom {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   140
     * int} values from this generator and/or one split from it; each value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   141
     * conforms to the given origin (inclusive) and bound (exclusive).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   142
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   143
     * @implNote This method is implemented to be equivalent to {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   144
     * ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   145
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   146
     * @param randomNumberOrigin the origin (inclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   147
     * @param randomNumberBound the bound (exclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   148
     * @return a stream of pseudorandom {@code int} values,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   149
     *         each with the given origin (inclusive) and bound (exclusive)
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   150
     * @throws IllegalArgumentException if {@code randomNumberOrigin}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   151
     *         is greater than or equal to {@code randomNumberBound}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   152
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   153
    public IntStream ints(int randomNumberOrigin, int randomNumberBound) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   154
	RngSupport.checkRange(randomNumberOrigin, randomNumberBound);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   155
        return StreamSupport.intStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   156
            (makeIntsSpliterator(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   157
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   158
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   159
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   160
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   161
     * Returns a stream producing the given {@code streamSize} number
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   162
     * of pseudorandom {@code long} values from this generator and/or
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   163
     * one split from it.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   164
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   165
     * @param streamSize the number of values to generate
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   166
     * @return a stream of pseudorandom {@code long} values
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   167
     * @throws IllegalArgumentException if {@code streamSize} is
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   168
     *         less than zero
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   169
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   170
    public LongStream longs(long streamSize) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   171
	RngSupport.checkStreamSize(streamSize);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   172
        return StreamSupport.longStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   173
            (makeLongsSpliterator(0L, streamSize, Long.MAX_VALUE, 0L),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   174
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   175
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   176
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   177
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   178
     * Returns an effectively unlimited stream of pseudorandom {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   179
     * long} values from this generator and/or one split from it.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   180
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   181
     * @implNote This method is implemented to be equivalent to {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   182
     * longs(Long.MAX_VALUE)}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   183
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   184
     * @return a stream of pseudorandom {@code long} values
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   185
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   186
    public LongStream longs() {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   187
        return StreamSupport.longStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   188
            (makeLongsSpliterator(0L, Long.MAX_VALUE, Long.MAX_VALUE, 0L),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   189
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   190
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   191
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   192
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   193
     * Returns a stream producing the given {@code streamSize} number of
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   194
     * pseudorandom {@code long} values from this generator and/or one split
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   195
     * from it; each value conforms to the given origin (inclusive) and bound
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   196
     * (exclusive).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   197
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   198
     * @param streamSize the number of values to generate
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   199
     * @param randomNumberOrigin the origin (inclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   200
     * @param randomNumberBound the bound (exclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   201
     * @return a stream of pseudorandom {@code long} values,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   202
     *         each with the given origin (inclusive) and bound (exclusive)
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   203
     * @throws IllegalArgumentException if {@code streamSize} is
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   204
     *         less than zero, or {@code randomNumberOrigin}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   205
     *         is greater than or equal to {@code randomNumberBound}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   206
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   207
    public LongStream longs(long streamSize, long randomNumberOrigin,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   208
			     long randomNumberBound) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   209
	RngSupport.checkStreamSize(streamSize);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   210
	RngSupport.checkRange(randomNumberOrigin, randomNumberBound);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   211
        return StreamSupport.longStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   212
            (makeLongsSpliterator(0L, streamSize, randomNumberOrigin, randomNumberBound),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   213
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   214
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   215
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   216
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   217
     * Returns an effectively unlimited stream of pseudorandom {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   218
     * long} values from this generator and/or one split from it; each value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   219
     * conforms to the given origin (inclusive) and bound (exclusive).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   220
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   221
     * @implNote This method is implemented to be equivalent to {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   222
     * longs(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   223
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   224
     * @param randomNumberOrigin the origin (inclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   225
     * @param randomNumberBound the bound (exclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   226
     * @return a stream of pseudorandom {@code long} values,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   227
     *         each with the given origin (inclusive) and bound (exclusive)
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   228
     * @throws IllegalArgumentException if {@code randomNumberOrigin}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   229
     *         is greater than or equal to {@code randomNumberBound}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   230
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   231
    public LongStream longs(long randomNumberOrigin, long randomNumberBound) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   232
	RngSupport.checkRange(randomNumberOrigin, randomNumberBound);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   233
        return StreamSupport.longStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   234
            (makeLongsSpliterator(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   235
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   236
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   237
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   238
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   239
     * Returns a stream producing the given {@code streamSize} number of
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   240
     * pseudorandom {@code double} values from this generator and/or one split
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   241
     * from it; each value is between zero (inclusive) and one (exclusive).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   242
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   243
     * @param streamSize the number of values to generate
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   244
     * @return a stream of {@code double} values
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   245
     * @throws IllegalArgumentException if {@code streamSize} is
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   246
     *         less than zero
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   247
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   248
    public DoubleStream doubles(long streamSize) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   249
	RngSupport.checkStreamSize(streamSize);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   250
        return StreamSupport.doubleStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   251
            (makeDoublesSpliterator(0L, streamSize, Double.MAX_VALUE, 0.0),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   252
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   253
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   254
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   255
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   256
     * Returns an effectively unlimited stream of pseudorandom {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   257
     * double} values from this generator and/or one split from it; each value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   258
     * is between zero (inclusive) and one (exclusive).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   259
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   260
     * @implNote This method is implemented to be equivalent to {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   261
     * doubles(Long.MAX_VALUE)}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   262
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   263
     * @return a stream of pseudorandom {@code double} values
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   264
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   265
    public DoubleStream doubles() {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   266
        return StreamSupport.doubleStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   267
            (makeDoublesSpliterator(0L, Long.MAX_VALUE, Double.MAX_VALUE, 0.0),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   268
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   269
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   270
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   271
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   272
     * Returns a stream producing the given {@code streamSize} number of
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   273
     * pseudorandom {@code double} values from this generator and/or one split
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   274
     * from it; each value conforms to the given origin (inclusive) and bound
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   275
     * (exclusive).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   276
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   277
     * @param streamSize the number of values to generate
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   278
     * @param randomNumberOrigin the origin (inclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   279
     * @param randomNumberBound the bound (exclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   280
     * @return a stream of pseudorandom {@code double} values,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   281
     *         each with the given origin (inclusive) and bound (exclusive)
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   282
     * @throws IllegalArgumentException if {@code streamSize} is
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   283
     *         less than zero
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   284
     * @throws IllegalArgumentException if {@code randomNumberOrigin}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   285
     *         is greater than or equal to {@code randomNumberBound}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   286
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   287
    public DoubleStream doubles(long streamSize, double randomNumberOrigin,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   288
				 double randomNumberBound) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   289
	RngSupport.checkStreamSize(streamSize);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   290
	RngSupport.checkRange(randomNumberOrigin, randomNumberBound);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   291
        return StreamSupport.doubleStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   292
            (makeDoublesSpliterator(0L, streamSize, randomNumberOrigin, randomNumberBound),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   293
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   294
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   295
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   296
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   297
     * Returns an effectively unlimited stream of pseudorandom {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   298
     * double} values from this generator and/or one split from it; each value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   299
     * conforms to the given origin (inclusive) and bound (exclusive).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   300
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   301
     * @implNote This method is implemented to be equivalent to {@code
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   302
     * doubles(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   303
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   304
     * @param randomNumberOrigin the origin (inclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   305
     * @param randomNumberBound the bound (exclusive) of each random value
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   306
     * @return a stream of pseudorandom {@code double} values,
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   307
     *         each with the given origin (inclusive) and bound (exclusive)
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   308
     * @throws IllegalArgumentException if {@code randomNumberOrigin}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   309
     *         is greater than or equal to {@code randomNumberBound}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   310
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   311
    public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   312
	RngSupport.checkRange(randomNumberOrigin, randomNumberBound);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   313
        return StreamSupport.doubleStream
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   314
            (makeDoublesSpliterator(0L, Long.MAX_VALUE, randomNumberOrigin, randomNumberBound),
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   315
             false);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   316
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   317
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   318
}