newrandom/SplittableRng.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) 2016, 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
// package java.util;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    26
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    27
import java.util.stream.Stream;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    28
import java.util.stream.StreamSupport;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    29
import java.util.stream.IntStream;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    30
import java.util.stream.LongStream;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    31
import java.util.stream.DoubleStream;
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    32
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    33
/**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    34
 * This interface is designed to provide a common protocol for objects
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    35
 * that generate sequences of pseudorandom numbers (or Boolean values)
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    36
 * and furthermore can be <it>split</it> into two objects (the original
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    37
 * one and a new one) each of which obey that same protocol (and therefore
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    38
 * can be recursively split indefinitely).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    39
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    40
 * <p>Ideally, all {@code SplittableRNG} objects produced by recursive
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    41
 * splitting from a single original {@code SplittableRNG} object are
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    42
 * statistically independent of one another and individually uniform.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    43
 * Therefore we would expect the set of values collectively generated
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    44
 * by a set of such objects to have the same statistical properties as
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    45
 * if the same quantity of values were generated by a single thread
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    46
 * using a single {@code SplittableRNG} object.  In practice, one must
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    47
 * settle for some approximation to independence and uniformity.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    48
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    49
 * <p>Methods are provided to perform a single splitting operation and
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    50
 * also to produce a stream of generators split off from the original
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    51
 * (by either iterative or recursive splitting, or a combination).
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    52
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    53
 * <p>An implementation of the {@code SplittableRng} interface must provide
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    54
 * concrete definitions for the methods {@code nextInt()}, {@code nextLong},
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    55
 * {@code period()}, {@code split()}, {@code split(SplittableRng)},
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    56
 * {@code splits()}, {@code splits(long)}, {@code splits(SplittableRng)},
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    57
 * and {@code splits(long, SplittableRng)}.  Perhaps the most convenient
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    58
 * way to implement this interface is to extend the abstract class
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    59
 * {@link java.util.AbstractSplittableRng}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    60
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    61
 * <p>Objects that implement {@code java.util.SplittableRNG} are
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    62
 * typically not cryptographically secure.  Consider instead using
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    63
 * {@link java.security.SecureRandom} to get a cryptographically
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    64
 * secure pseudo-random number generator for use by
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    65
 * security-sensitive applications.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    66
 *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    67
 * @author  Guy Steele
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    68
 * @since   1.9
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    69
 */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    70
interface SplittableRng extends StreamableRng {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    71
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    72
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    73
     * Returns a new pseudorandom number generator, split off from
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    74
     * this one, that implements the {@code Rng} and {@code SplittableRng}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    75
     * interfaces.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    76
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    77
     * This pseudorandom number generator may be used as a source of
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    78
     * pseudorandom bits used to initialize the state the new one.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    79
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    80
     * @return a new object that implements the {@code Rng} and
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    81
     *         {@code SplittableRng} interfaces
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    82
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    83
    SplittableRng split();
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    84
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    85
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    86
     * Returns a new pseudorandom number generator, split off from
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    87
     * this one, that implements the {@code Rng} and {@code SplittableRng}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    88
     * interfaces.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    89
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    90
     * @param source a {@code SplittableRng} instance to be used instead
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    91
     *               of this one as a source of pseudorandom bits used to
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    92
     *               initialize the state of the new ones.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    93
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    94
     * @return an object that implements the {@code Rng} and
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    95
     *         {@code SplittableRng} interfaces
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    96
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    97
    SplittableRng split(SplittableRng source);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    98
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
    99
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   100
     * Returns an effectively unlimited stream of new pseudorandom
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   101
     * number generators, each of which implements the {@code SplittableRng}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   102
     * interface.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   103
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   104
     * This pseudorandom number generator may be used as a source of
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   105
     * pseudorandom bits used to initialize the state the new ones.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   106
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   107
     * @implNote It is permitted to implement this method in a manner
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   108
     * equivalent to {@code splits(Long.MAX_VALUE)}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   109
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   110
     * @return a stream of {@code SplittableRng} objects
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   111
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   112
    default Stream<SplittableRng> splits() {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   113
	return this.splits(this);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   114
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   115
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   116
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   117
     * Returns a stream producing the given {@code streamSize} number of
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   118
     * new pseudorandom number generators, each of which implements the
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   119
     * {@code SplittableRng} interface.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   120
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   121
     * This pseudorandom number generator may be used as a source of
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   122
     * pseudorandom bits used to initialize the state the new ones.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   123
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   124
     * @param streamSize the number of values to generate
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   125
     * @return a stream of {@code SplittableRng} objects
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   126
     * @throws IllegalArgumentException if {@code streamSize} is
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   127
     *         less than zero
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   128
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   129
    Stream<SplittableRng> splits(long streamSize);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   130
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   131
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   132
     * Returns an effectively unlimited stream of new pseudorandom
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   133
     * number generators, each of which implements the {@code SplittableRng}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   134
     * interface.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   135
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   136
     * @implNote It is permitted to implement this method in a manner
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   137
     * equivalent to {@code splits(Long.MAX_VALUE, source)}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   138
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   139
     * @param source a {@code SplittableRng} instance to be used instead
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   140
     *               of this one as a source of pseudorandom bits used to
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   141
     *               initialize the state of the new ones.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   142
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   143
     * @return a stream of {@code SplittableRng} objects
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   144
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   145
    Stream<SplittableRng> splits(SplittableRng source);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   146
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   147
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   148
     * Returns a stream producing the given {@code streamSize} number of
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   149
     * new pseudorandom number generators, each of which implements the
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   150
     * {@code SplittableRng} interface.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   151
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   152
     * @param streamSize the number of values to generate
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   153
     * @param source a {@code SplittableRng} instance to be used instead
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   154
     *               of this one as a source of pseudorandom bits used to
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   155
     *               initialize the state of the new ones.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   156
     * @return a stream of {@code SplittableRng} objects
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   157
     * @throws IllegalArgumentException if {@code streamSize} is
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   158
     *         less than zero
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   159
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   160
    Stream<SplittableRng> splits(long streamSize, SplittableRng source);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   161
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   162
    /**
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   163
     * Returns an effectively unlimited stream of new pseudorandom
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   164
     * number generators, each of which implements the {@code Rng}
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   165
     * interface.  Ideally the generators in the stream will appear
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   166
     * to be statistically independent.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   167
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   168
     * @implNote The default implementation calls {@code splits()}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   169
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   170
     * @return a stream of objects that implement the {@code Rng} interface
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   171
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   172
    default Stream<Rng> rngs() {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   173
	return this.splits().map(x -> (Rng)x);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   174
    }
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
     * Returns a stream producing the given {@code streamSize} number of
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   178
     * new pseudorandom number generators, each of which implements the
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   179
     * {@code Rng} interface.  Ideally the generators in the stream will
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   180
     * appear to be statistically independent.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   181
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   182
     * @implNote The default implementation calls {@code splits(streamSize)}.
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   183
     *
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   184
     * @param streamSize the number of generators to generate
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   185
     * @return a stream of objects that implement the {@code Rng} interface
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   186
     * @throws IllegalArgumentException if {@code streamSize} is
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   187
     *         less than zero
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   188
     */
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   189
    default Stream<Rng> rngs(long streamSize) {
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   190
	return this.splits(streamSize).map(x -> (Rng)x);
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   191
    }
6d87e9f7a1ec Initial comment in newrandom/
briangoetz
parents:
diff changeset
   192
}