author | jlaskey |
Thu, 27 Jun 2019 18:30:27 -0300 | |
branch | JDK-8193209-branch |
changeset 57437 | f02ffcb61dce |
parent 57388 | src/java.base/share/classes/java/util/Rng.java@b1e6bc96af3d |
permissions | -rw-r--r-- |
57388 | 1 |
/* |
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
57388 | 4 |
* |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
57388 | 10 |
* |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
15 |
* accompanied this code). |
57388 | 16 |
* |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
57388 | 20 |
* |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
23 |
* questions. |
57388 | 24 |
*/ |
25 |
||
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
26 |
package java.util.random; |
57388 | 27 |
|
28 |
import java.math.BigInteger; |
|
29 |
import java.util.stream.DoubleStream; |
|
30 |
import java.util.stream.IntStream; |
|
31 |
import java.util.stream.LongStream; |
|
32 |
||
33 |
/** |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
34 |
* The {@link RandomNumberGenerator} interface is designed to provide a common protocol for objects |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
35 |
* that generate random or (more typically) pseudorandom sequences of numbers (or Boolean values). |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
36 |
* Such a sequence may be obtained by either repeatedly invoking a method that returns a single |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
37 |
* (pseudo)randomly chosen value, or by invoking a method that returns a stream of (pseudo)randomly |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
38 |
* chosen values. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
39 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
40 |
* Ideally, given an implicitly or explicitly specified range of values, each value would be chosen |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
41 |
* independently and uniformly from that range. In practice, one may have to settle for some |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
42 |
* approximation to independence and uniformity. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
43 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
44 |
* In the case of {@code int}, {@code long}, and {@link Boolean} values, if there is no explicit |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
45 |
* specification of range, then the range includes all possible values of the type. In the case of |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
46 |
* {@code float} and {@code double} values, a value is always chosen from the set of |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
47 |
* 2<sup><i>w</i></sup> values between 0.0 (inclusive) and 1.0 (exclusive), where <i>w</i> is 23 for |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
48 |
* {@code float} values and 52 for {@code double} values, such that adjacent values differ by |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
49 |
* 2<sup>−<i>w</i></sup>; if an explicit range is specified, then the chosen number is |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
50 |
* computationally scaled and translated so as to appear to have been chosen from that range. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
51 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
52 |
* Each method that returns a stream produces a stream of values each of which is chosen in the same |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
53 |
* manner as for a method that returns a single (pseudo)randomly chosen value. For example, if |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
54 |
* {@code r} implements {@link RandomNumberGenerator}, then the method call {@code r.ints(100)} |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
55 |
* returns a stream of 100 {@code int} values. These are not necessarily the exact same values that |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
56 |
* would have been returned if instead {@code r.nextInt()} had been called 100 times; all that is |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
57 |
* guaranteed is that each value in the stream is chosen in a similar (pseudo)random manner from the |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
58 |
* same range. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
59 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
60 |
* Every object that implements the {@link RandomNumberGenerator} interface is assumed to contain a |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
61 |
* finite amount of state. Using such an object to generate a pseudorandomly chosen value alters |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
62 |
* its state. The number of distinct possible states of such an object is called its |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
63 |
* <i>period</i>. (Some implementations of the {@link RandomNumberGenerator} interface |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
64 |
* may be truly random rather than pseudorandom, for example relying on the statistical behavior of |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
65 |
* a physical object to derive chosen values. Such implementations do not have a fixed period.) |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
66 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
67 |
* As a rule, objects that implement the {@link RandomNumberGenerator} interface need not be |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
68 |
* thread-safe. It is recommended that multithreaded applications use either {@link |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
69 |
* ThreadLocalRandom} or (preferably) pseudorandom number generators that implement the {@link |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
70 |
* SplittableRNG} or {@link JumpableRNG} interface. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
71 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
72 |
* To implement this interface, a class only needs to provide concrete definitions for the methods |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
73 |
* {@code nextLong()} and {@code period()}. Default implementations are provided for all other |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
74 |
* methods (but it may be desirable to override some of them, especially {@code nextInt()} if the |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
75 |
* underlying algorithm is {@code int}-based). Moerover, it may be preferable instead to implement |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
76 |
* another interface such as {@link JumpableRNG} or {@link LeapableRNG}, or to extend an abstract |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
77 |
* class such as {@link AbstractSplittableRNG} or {@link AbstractArbitrarilyJumpableRNG}. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
78 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
79 |
* Objects that implement {@link RandomNumberGenerator} are typically not cryptographically secure. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
80 |
* Consider instead using {@link java.security.SecureRandom} to get a cryptographically secure |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
81 |
* pseudorandom number generator for use by security-sensitive applications. Note, however, that |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
82 |
* {@code java.security.SecureRandom} does implement the {@link RandomNumberGenerator} interface, so |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
83 |
* that instances of {@code java.security.SecureRandom} may be used interchangeably with other types |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
84 |
* of pseudorandom generators in applications that do not require a secure generator. |
57388 | 85 |
* |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
86 |
* @since 14 |
57388 | 87 |
*/ |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
88 |
public interface RandomNumberGenerator { |
57388 | 89 |
|
90 |
/** |
|
91 |
* Returns an effectively unlimited stream of pseudorandomly chosen |
|
92 |
* {@code double} values. |
|
93 |
* |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
94 |
* @return a stream of pseudorandomly chosen {@code double} values |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
95 |
* |
57388 | 96 |
* @implNote It is permitted to implement this method in a manner |
97 |
* equivalent to {@code doubles(Long.MAX_VALUE)}. |
|
98 |
* |
|
99 |
* @implNote The default implementation produces a sequential stream |
|
100 |
* that repeatedly calls {@code nextDouble()}. |
|
101 |
*/ |
|
102 |
default DoubleStream doubles() { |
|
103 |
return DoubleStream.generate(this::nextDouble).sequential(); |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Returns an effectively unlimited stream of pseudorandomly chosen |
|
108 |
* {@code double} values, where each value is between the specified |
|
109 |
* origin (inclusive) and the specified bound (exclusive). |
|
110 |
* |
|
111 |
* @param randomNumberOrigin the least value that can be produced |
|
112 |
* @param randomNumberBound the upper bound (exclusive) for each value produced |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
113 |
* |
57388 | 114 |
* @return a stream of pseudorandomly chosen {@code double} values, each between |
115 |
* the specified origin (inclusive) and the specified bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
116 |
* |
57388 | 117 |
* @throws IllegalArgumentException if {@code randomNumberOrigin} |
118 |
* is greater than or equal to {@code randomNumberBound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
119 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
120 |
* @implNote It is permitted to implement this method in a manner |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
121 |
* equivalent to |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
122 |
* {@code doubles(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
123 |
* @implNote The default implementation produces a sequential stream that repeatedly |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
124 |
* calls {@code nextDouble(randomNumberOrigin, randomNumberBound)}. |
57388 | 125 |
*/ |
126 |
default DoubleStream doubles(double randomNumberOrigin, double randomNumberBound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
127 |
RNGSupport.checkRange(randomNumberOrigin, randomNumberBound); |
57388 | 128 |
return DoubleStream.generate(() -> nextDouble(randomNumberOrigin, randomNumberBound)).sequential(); |
129 |
} |
|
130 |
||
131 |
/** |
|
132 |
* Returns a stream producing the given {@code streamSize} number of |
|
133 |
* pseudorandomly chosen {@code double} values. |
|
134 |
* |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
135 |
* @param streamSize the number of values to generate |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
136 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
137 |
* @return a stream of pseudorandomly chosen {@code double} values |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
138 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
139 |
* @throws IllegalArgumentException if {@code streamSize} is |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
140 |
* less than zero |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
141 |
* |
57388 | 142 |
* @implNote The default implementation produces a sequential stream |
143 |
* that repeatedly calls {@code nextDouble()}. |
|
144 |
*/ |
|
145 |
default DoubleStream doubles(long streamSize) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
146 |
RNGSupport.checkStreamSize(streamSize); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
147 |
return doubles().limit(streamSize); |
57388 | 148 |
} |
149 |
||
150 |
/** |
|
151 |
* Returns a stream producing the given {@code streamSize} number of |
|
152 |
* pseudorandomly chosen {@code double} values, where each value is between |
|
153 |
* the specified origin (inclusive) and the specified bound (exclusive). |
|
154 |
* |
|
155 |
* @param streamSize the number of values to generate |
|
156 |
* @param randomNumberOrigin the least value that can be produced |
|
157 |
* @param randomNumberBound the upper bound (exclusive) for each value produced |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
158 |
* |
57388 | 159 |
* @return a stream of pseudorandomly chosen {@code double} values, each between |
160 |
* the specified origin (inclusive) and the specified bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
161 |
* |
57388 | 162 |
* @throws IllegalArgumentException if {@code streamSize} is |
163 |
* less than zero, or {@code randomNumberOrigin} |
|
164 |
* is greater than or equal to {@code randomNumberBound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
165 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
166 |
* @implNote The default implementation produces a sequential stream |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
167 |
* that repeatedly calls {@code nextDouble(randomNumberOrigin, randomNumberBound)}. |
57388 | 168 |
*/ |
169 |
default DoubleStream doubles(long streamSize, double randomNumberOrigin, |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
170 |
double randomNumberBound) { |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
171 |
RNGSupport.checkStreamSize(streamSize); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
172 |
RNGSupport.checkRange(randomNumberOrigin, randomNumberBound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
173 |
return doubles(randomNumberOrigin, randomNumberBound).limit(streamSize); |
57388 | 174 |
} |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
175 |
|
57388 | 176 |
/** |
177 |
* Returns an effectively unlimited stream of pseudorandomly chosen |
|
178 |
* {@code int} values. |
|
179 |
* |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
180 |
* @return a stream of pseudorandomly chosen {@code int} values |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
181 |
* |
57388 | 182 |
* @implNote It is permitted to implement this method in a manner |
183 |
* equivalent to {@code ints(Long.MAX_VALUE)}. |
|
184 |
* @implNote The default implementation produces a sequential stream |
|
185 |
* that repeatedly calls {@code nextInt()}. |
|
186 |
*/ |
|
187 |
default IntStream ints() { |
|
188 |
return IntStream.generate(this::nextInt).sequential(); |
|
189 |
} |
|
190 |
||
191 |
/** |
|
192 |
* Returns an effectively unlimited stream of pseudorandomly chosen |
|
193 |
* {@code int} values, where each value is between the specified |
|
194 |
* origin (inclusive) and the specified bound (exclusive). |
|
195 |
* |
|
196 |
* @param randomNumberOrigin the least value that can be produced |
|
197 |
* @param randomNumberBound the upper bound (exclusive) for each value produced |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
198 |
* |
57388 | 199 |
* @return a stream of pseudorandomly chosen {@code int} values, each between |
200 |
* the specified origin (inclusive) and the specified bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
201 |
* |
57388 | 202 |
* @throws IllegalArgumentException if {@code randomNumberOrigin} |
203 |
* is greater than or equal to {@code randomNumberBound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
204 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
205 |
* @implNote It is permitted to implement this method in a manner equivalent to |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
206 |
* {@code ints(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
207 |
* @implNote The default implementation produces a sequential stream that repeatedly |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
208 |
* calls {@code nextInt(randomNumberOrigin, randomNumberBound)}. |
57388 | 209 |
*/ |
210 |
default IntStream ints(int randomNumberOrigin, int randomNumberBound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
211 |
RNGSupport.checkRange(randomNumberOrigin, randomNumberBound); |
57388 | 212 |
return IntStream.generate(() -> nextInt(randomNumberOrigin, randomNumberBound)).sequential(); |
213 |
} |
|
214 |
||
215 |
/** |
|
216 |
* Returns a stream producing the given {@code streamSize} number of |
|
217 |
* pseudorandomly chosen {@code int} values. |
|
218 |
* |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
219 |
* @param streamSize the number of values to generate |
57388 | 220 |
* |
221 |
* @return a stream of pseudorandomly chosen {@code int} values |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
222 |
* |
57388 | 223 |
* @throws IllegalArgumentException if {@code streamSize} is |
224 |
* less than zero |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
225 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
226 |
* @implNote The default implementation produces a sequential stream |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
227 |
* that repeatedly calls {@code nextInt()}. |
57388 | 228 |
*/ |
229 |
default IntStream ints(long streamSize) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
230 |
RNGSupport.checkStreamSize(streamSize); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
231 |
return ints().limit(streamSize); |
57388 | 232 |
} |
233 |
||
234 |
/** |
|
235 |
* Returns a stream producing the given {@code streamSize} number of |
|
236 |
* pseudorandomly chosen {@code int} values, where each value is between |
|
237 |
* the specified origin (inclusive) and the specified bound (exclusive). |
|
238 |
* |
|
239 |
* @param streamSize the number of values to generate |
|
240 |
* @param randomNumberOrigin the least value that can be produced |
|
241 |
* @param randomNumberBound the upper bound (exclusive) for each value produced |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
242 |
* |
57388 | 243 |
* @return a stream of pseudorandomly chosen {@code int} values, each between |
244 |
* the specified origin (inclusive) and the specified bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
245 |
* |
57388 | 246 |
* @throws IllegalArgumentException if {@code streamSize} is |
247 |
* less than zero, or {@code randomNumberOrigin} |
|
248 |
* is greater than or equal to {@code randomNumberBound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
249 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
250 |
* @implNote The default implementation produces a sequential stream that repeatedly |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
251 |
* calls {@code nextInt(randomNumberOrigin, randomNumberBound)}. |
57388 | 252 |
*/ |
253 |
default IntStream ints(long streamSize, int randomNumberOrigin, |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
254 |
int randomNumberBound) { |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
255 |
RNGSupport.checkStreamSize(streamSize); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
256 |
RNGSupport.checkRange(randomNumberOrigin, randomNumberBound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
257 |
return ints(randomNumberOrigin, randomNumberBound).limit(streamSize); |
57388 | 258 |
} |
259 |
||
260 |
/** |
|
261 |
* Returns an effectively unlimited stream of pseudorandomly chosen |
|
262 |
* {@code long} values. |
|
263 |
* |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
264 |
* @return a stream of pseudorandomly chosen {@code long} values |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
265 |
* |
57388 | 266 |
* @implNote It is permitted to implement this method in a manner |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
267 |
* equivalent to {@code longs(Long.MAX_VALUE)}. |
57388 | 268 |
* @implNote The default implementation produces a sequential stream |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
269 |
* that repeatedly calls {@code nextLong()}. |
57388 | 270 |
*/ |
271 |
default LongStream longs() { |
|
272 |
return LongStream.generate(this::nextLong).sequential(); |
|
273 |
} |
|
274 |
||
275 |
/** |
|
276 |
* Returns an effectively unlimited stream of pseudorandomly chosen |
|
277 |
* {@code long} values, where each value is between the specified |
|
278 |
* origin (inclusive) and the specified bound (exclusive). |
|
279 |
* |
|
280 |
* @param randomNumberOrigin the least value that can be produced |
|
281 |
* @param randomNumberBound the upper bound (exclusive) for each value produced |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
282 |
* |
57388 | 283 |
* @return a stream of pseudorandomly chosen {@code long} values, each between |
284 |
* the specified origin (inclusive) and the specified bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
285 |
* |
57388 | 286 |
* @throws IllegalArgumentException if {@code randomNumberOrigin} |
287 |
* is greater than or equal to {@code randomNumberBound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
288 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
289 |
* @implNote It is permitted to implement this method in a manner |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
290 |
* equivalent to {@code longs(Long.MAX_VALUE, randomNumberOrigin, randomNumberBound)}. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
291 |
* @implNote The default implementation produces a sequential stream that repeatedly |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
292 |
* calls {@code nextLong(randomNumberOrigin, randomNumberBound)}. |
57388 | 293 |
*/ |
294 |
default LongStream longs(long randomNumberOrigin, long randomNumberBound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
295 |
RNGSupport.checkRange(randomNumberOrigin, randomNumberBound); |
57388 | 296 |
return LongStream.generate(() -> nextLong(randomNumberOrigin, randomNumberBound)).sequential(); |
297 |
} |
|
298 |
||
299 |
/** |
|
300 |
* Returns a stream producing the given {@code streamSize} number of |
|
301 |
* pseudorandomly chosen {@code long} values. |
|
302 |
* |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
303 |
* @param streamSize the number of values to generate |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
304 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
305 |
* @return a stream of pseudorandomly chosen {@code long} values |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
306 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
307 |
* @throws IllegalArgumentException if {@code streamSize} is |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
308 |
* less than zero |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
309 |
* |
57388 | 310 |
* @implNote The default implementation produces a sequential stream |
311 |
* that repeatedly calls {@code nextLong()}. |
|
312 |
*/ |
|
313 |
default LongStream longs(long streamSize) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
314 |
RNGSupport.checkStreamSize(streamSize); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
315 |
return longs().limit(streamSize); |
57388 | 316 |
} |
317 |
||
318 |
/** |
|
319 |
* Returns a stream producing the given {@code streamSize} number of |
|
320 |
* pseudorandomly chosen {@code long} values, where each value is between |
|
321 |
* the specified origin (inclusive) and the specified bound (exclusive). |
|
322 |
* |
|
323 |
* @param streamSize the number of values to generate |
|
324 |
* @param randomNumberOrigin the least value that can be produced |
|
325 |
* @param randomNumberBound the upper bound (exclusive) for each value produced |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
326 |
* |
57388 | 327 |
* @return a stream of pseudorandomly chosen {@code long} values, each between |
328 |
* the specified origin (inclusive) and the specified bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
329 |
* |
57388 | 330 |
* @throws IllegalArgumentException if {@code streamSize} is |
331 |
* less than zero, or {@code randomNumberOrigin} |
|
332 |
* is greater than or equal to {@code randomNumberBound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
333 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
334 |
* @implNote The default implementation produces a sequential stream that repeatedly |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
335 |
* calls {@code nextLong(randomNumberOrigin, randomNumberBound)}. |
57388 | 336 |
*/ |
337 |
default LongStream longs(long streamSize, long randomNumberOrigin, |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
338 |
long randomNumberBound) { |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
339 |
RNGSupport.checkStreamSize(streamSize); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
340 |
RNGSupport.checkRange(randomNumberOrigin, randomNumberBound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
341 |
return longs(randomNumberOrigin, randomNumberBound).limit(streamSize); |
57388 | 342 |
} |
343 |
||
344 |
/** |
|
345 |
* Returns a pseudorandomly chosen {@code boolean} value. |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
346 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
347 |
* The default implementation tests the high-order bit (sign bit) of a value produced by {@code |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
348 |
* nextInt()}, on the grounds that some algorithms for pseudorandom number generation produce |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
349 |
* values whose high-order bits have better statistical quality than the low-order bits. |
57388 | 350 |
* |
351 |
* @return a pseudorandomly chosen {@code boolean} value |
|
352 |
*/ |
|
353 |
default boolean nextBoolean() { |
|
354 |
return nextInt() < 0; |
|
355 |
} |
|
356 |
||
357 |
/** |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
358 |
* Returns a pseudorandom {@code float} value between zero (inclusive) and one (exclusive). |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
359 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
360 |
* The default implementation uses the 24 high-order bits from a call to {@code nextInt()}. |
57388 | 361 |
* |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
362 |
* @return a pseudorandom {@code float} value between zero (inclusive) and one (exclusive) |
57388 | 363 |
*/ |
364 |
default float nextFloat() { |
|
365 |
return (nextInt() >>> 8) * 0x1.0p-24f; |
|
366 |
} |
|
367 |
||
368 |
/** |
|
369 |
* Returns a pseudorandomly chosen {@code float} value between zero |
|
370 |
* (inclusive) and the specified bound (exclusive). |
|
371 |
* |
|
372 |
* @param bound the upper bound (exclusive) for the returned value. |
|
373 |
* Must be positive and finite |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
374 |
* |
57388 | 375 |
* @return a pseudorandomly chosen {@code float} value between |
376 |
* zero (inclusive) and the bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
377 |
* |
57388 | 378 |
* @throws IllegalArgumentException if {@code bound} is not |
379 |
* positive and finite |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
380 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
381 |
* @implNote The default implementation simply calls |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
382 |
* {@code RNGSupport.checkBound(bound)} and then |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
383 |
* {@code RNGSupport.boundedNextFloat(this, bound)}. |
57388 | 384 |
*/ |
385 |
default float nextFloat(float bound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
386 |
RNGSupport.checkBound(bound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
387 |
return RNGSupport.boundedNextFloat(this, bound); |
57388 | 388 |
} |
389 |
||
390 |
/** |
|
391 |
* Returns a pseudorandomly chosen {@code float} value between the |
|
392 |
* specified origin (inclusive) and the specified bound (exclusive). |
|
393 |
* |
|
394 |
* @param origin the least value that can be returned |
|
395 |
* @param bound the upper bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
396 |
* |
57388 | 397 |
* @return a pseudorandomly chosen {@code float} value between the |
398 |
* origin (inclusive) and the bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
399 |
* |
57388 | 400 |
* @throws IllegalArgumentException unless {@code origin} is finite, |
401 |
* {@code bound} is finite, and {@code origin} is less than |
|
402 |
* {@code bound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
403 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
404 |
* @implNote The default implementation simply calls |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
405 |
* {@code RNGSupport.checkRange(origin, bound)} and then |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
406 |
* {@code RNGSupport.boundedNextFloat(this, origin, bound)}. |
57388 | 407 |
*/ |
408 |
default float nextFloat(float origin, float bound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
409 |
RNGSupport.checkRange(origin, bound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
410 |
return RNGSupport.boundedNextFloat(this, origin, bound); |
57388 | 411 |
} |
412 |
||
413 |
/** |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
414 |
* Returns a pseudorandom {@code double} value between zero (inclusive) and one (exclusive). |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
415 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
416 |
* The default implementation uses the 53 high-order bits from a call to {@code nextLong()}. |
57388 | 417 |
* |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
418 |
* @return a pseudorandom {@code double} value between zero (inclusive) and one (exclusive) |
57388 | 419 |
*/ |
420 |
default double nextDouble() { |
|
421 |
return (nextLong() >>> 11) * 0x1.0p-53; |
|
422 |
} |
|
423 |
||
424 |
/** |
|
425 |
* Returns a pseudorandomly chosen {@code double} value between zero |
|
426 |
* (inclusive) and the specified bound (exclusive). |
|
427 |
* |
|
428 |
* @param bound the upper bound (exclusive) for the returned value. |
|
429 |
* Must be positive and finite |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
430 |
* |
57388 | 431 |
* @return a pseudorandomly chosen {@code double} value between |
432 |
* zero (inclusive) and the bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
433 |
* |
57388 | 434 |
* @throws IllegalArgumentException if {@code bound} is not |
435 |
* positive and finite |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
436 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
437 |
* @implNote The default implementation simply calls |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
438 |
* {@code RNGSupport.checkBound(bound)} and then |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
439 |
* {@code RNGSupport.boundedNextDouble(this, bound)}. |
57388 | 440 |
*/ |
441 |
default double nextDouble(double bound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
442 |
RNGSupport.checkBound(bound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
443 |
return RNGSupport.boundedNextDouble(this, bound); |
57388 | 444 |
} |
445 |
||
446 |
/** |
|
447 |
* Returns a pseudorandomly chosen {@code double} value between the |
|
448 |
* specified origin (inclusive) and the specified bound (exclusive). |
|
449 |
* |
|
450 |
* @param origin the least value that can be returned |
|
451 |
* @param bound the upper bound (exclusive) for the returned value |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
452 |
* |
57388 | 453 |
* @return a pseudorandomly chosen {@code double} value between the |
454 |
* origin (inclusive) and the bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
455 |
* |
57388 | 456 |
* @throws IllegalArgumentException unless {@code origin} is finite, |
457 |
* {@code bound} is finite, and {@code origin} is less than |
|
458 |
* {@code bound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
459 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
460 |
* @implNote The default implementation simply calls |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
461 |
* {@code RNGSupport.checkRange(origin, bound)} and then |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
462 |
* {@code RNGSupport.boundedNextDouble(this, origin, bound)}. |
57388 | 463 |
*/ |
464 |
default double nextDouble(double origin, double bound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
465 |
RNGSupport.checkRange(origin, bound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
466 |
return RNGSupport.boundedNextDouble(this, origin, bound); |
57388 | 467 |
} |
468 |
||
469 |
/** |
|
470 |
* Returns a pseudorandomly chosen {@code int} value. |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
471 |
* <p> |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
472 |
* The default implementation uses the 32 high-order bits from a call to {@code nextLong()}. |
57388 | 473 |
* |
474 |
* @return a pseudorandomly chosen {@code int} value |
|
475 |
*/ |
|
476 |
default public int nextInt() { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
477 |
return (int)(nextLong() >>> 32); |
57388 | 478 |
} |
479 |
||
480 |
/** |
|
481 |
* Returns a pseudorandomly chosen {@code int} value between |
|
482 |
* zero (inclusive) and the specified bound (exclusive). |
|
483 |
* |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
484 |
* @param bound the upper bound (exclusive) for the returned value. Must be positive. |
57388 | 485 |
* |
486 |
* @return a pseudorandomly chosen {@code int} value between |
|
487 |
* zero (inclusive) and the bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
488 |
* |
57388 | 489 |
* @throws IllegalArgumentException if {@code bound} is not positive |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
490 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
491 |
* @implNote The default implementation simply calls |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
492 |
* {@code RNGSupport.checkBound(bound)} and then |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
493 |
* {@code RNGSupport.boundedNextInt(this, bound)}. |
57388 | 494 |
*/ |
495 |
default int nextInt(int bound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
496 |
RNGSupport.checkBound(bound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
497 |
return RNGSupport.boundedNextInt(this, bound); |
57388 | 498 |
} |
499 |
||
500 |
/** |
|
501 |
* Returns a pseudorandomly chosen {@code int} value between the |
|
502 |
* specified origin (inclusive) and the specified bound (exclusive). |
|
503 |
* |
|
504 |
* @param origin the least value that can be returned |
|
505 |
* @param bound the upper bound (exclusive) for the returned value |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
506 |
* |
57388 | 507 |
* @return a pseudorandomly chosen {@code int} value between the |
508 |
* origin (inclusive) and the bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
509 |
* |
57388 | 510 |
* @throws IllegalArgumentException if {@code origin} is greater than |
511 |
* or equal to {@code bound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
512 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
513 |
* @implNote The default implementation simply calls |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
514 |
* {@code RNGSupport.checkRange(origin, bound)} and then |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
515 |
* {@code RNGSupport.boundedNextInt(this, origin, bound)}. |
57388 | 516 |
*/ |
517 |
default int nextInt(int origin, int bound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
518 |
RNGSupport.checkRange(origin, bound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
519 |
return RNGSupport.boundedNextInt(this, origin, bound); |
57388 | 520 |
} |
521 |
||
522 |
/** |
|
523 |
* Returns a pseudorandomly chosen {@code long} value. |
|
524 |
* |
|
525 |
* @return a pseudorandomly chosen {@code long} value |
|
526 |
*/ |
|
527 |
long nextLong(); |
|
528 |
||
529 |
/** |
|
530 |
* Returns a pseudorandomly chosen {@code long} value between |
|
531 |
* zero (inclusive) and the specified bound (exclusive). |
|
532 |
* |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
533 |
* @param bound the upper bound (exclusive) for the returned value. Must be positive. |
57388 | 534 |
* |
535 |
* @return a pseudorandomly chosen {@code long} value between |
|
536 |
* zero (inclusive) and the bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
537 |
* |
57388 | 538 |
* @throws IllegalArgumentException if {@code bound} is not positive |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
539 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
540 |
* @implNote The default implementation simply calls |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
541 |
* {@code RNGSupport.checkBound(bound)} and then |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
542 |
* {@code RNGSupport.boundedNextLong(this, bound)}. |
57388 | 543 |
*/ |
544 |
default long nextLong(long bound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
545 |
RNGSupport.checkBound(bound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
546 |
return RNGSupport.boundedNextLong(this, bound); |
57388 | 547 |
} |
548 |
||
549 |
/** |
|
550 |
* Returns a pseudorandomly chosen {@code long} value between the |
|
551 |
* specified origin (inclusive) and the specified bound (exclusive). |
|
552 |
* |
|
553 |
* @param origin the least value that can be returned |
|
554 |
* @param bound the upper bound (exclusive) for the returned value |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
555 |
* |
57388 | 556 |
* @return a pseudorandomly chosen {@code long} value between the |
557 |
* origin (inclusive) and the bound (exclusive) |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
558 |
* |
57388 | 559 |
* @throws IllegalArgumentException if {@code origin} is greater than |
560 |
* or equal to {@code bound} |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
561 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
562 |
* @implNote The default implementation simply calls |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
563 |
* {@code RNGSupport.checkRange(origin, bound)} and then |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
564 |
* {@code RNGSupport.boundedNextInt(this, origin, bound)}. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
565 |
* |
57388 | 566 |
*/ |
567 |
default long nextLong(long origin, long bound) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
568 |
RNGSupport.checkRange(origin, bound); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
569 |
return RNGSupport.boundedNextLong(this, origin, bound); |
57388 | 570 |
} |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
571 |
|
57388 | 572 |
/** |
573 |
* Returns a {@code double} value pseudorandomly chosen from |
|
574 |
* a Gaussian (normal) distribution whose mean is 0 and whose |
|
575 |
* standard deviation is 1. |
|
576 |
* |
|
577 |
* @return a {@code double} value pseudorandomly chosen from a |
|
578 |
* Gaussian distribution |
|
579 |
*/ |
|
580 |
default double nextGaussian() { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
581 |
return RNGSupport.computeNextGaussian(this); |
57388 | 582 |
} |
583 |
||
584 |
/** |
|
585 |
* Returns a {@code double} value pseudorandomly chosen from |
|
586 |
* a Gaussian (normal) distribution with a mean and |
|
587 |
* standard deviation specified by the arguments. |
|
588 |
* |
|
589 |
* @param mean the mean of the Gaussian distribution to be drawn from |
|
590 |
* @param stddev the standard deviation (square root of the variance) |
|
591 |
* of the Gaussian distribution to be drawn from |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
592 |
* |
57388 | 593 |
* @return a {@code double} value pseudorandomly chosen from the |
594 |
* specified Gaussian distribution |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
595 |
* |
57388 | 596 |
* @throws IllegalArgumentException if {@code stddev} is negative |
597 |
*/ |
|
598 |
default double nextGaussian(double mean, double stddev) { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
599 |
if (stddev < 0.0) throw new IllegalArgumentException("standard deviation must be non-negative"); |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
600 |
return mean + stddev * RNGSupport.computeNextGaussian(this); |
57388 | 601 |
} |
602 |
||
603 |
/** |
|
604 |
* Returns a nonnegative {@code double} value pseudorandomly chosen |
|
605 |
* from an exponential distribution whose mean is 1. |
|
606 |
* |
|
607 |
* @return a nonnegative {@code double} value pseudorandomly chosen from an |
|
608 |
* exponential distribution |
|
609 |
*/ |
|
610 |
default double nextExponential() { |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
611 |
return RNGSupport.computeNextExponential(this); |
57388 | 612 |
} |
613 |
||
614 |
/** |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
615 |
* Returns the period of this {@link RandomNumberGenerator} object. |
57388 | 616 |
* |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
617 |
* @return a {@link BigInteger} whose value is the number of distinct possible states of this |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
618 |
* {@link RandomNumberGenerator} object, or 0 if unknown, or negative if extremely |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
57388
diff
changeset
|
619 |
* large. |
57388 | 620 |
*/ |
621 |
BigInteger period(); |
|
622 |
||
623 |
/** |
|
624 |
* The value (0) returned by the {@code period()} method if the period is unknown. |
|
625 |
*/ |
|
626 |
static final BigInteger UNKNOWN_PERIOD = BigInteger.ZERO; |
|
627 |
||
628 |
/** |
|
629 |
* The (negative) value returned by the {@code period()} method if this generator |
|
630 |
* has no period because it is truly random rather than just pseudorandom. |
|
631 |
*/ |
|
632 |
static final BigInteger TRULY_RANDOM = BigInteger.valueOf(-1); |
|
633 |
||
634 |
/** |
|
635 |
* The (negative) value that may be returned by the {@code period()} method |
|
636 |
* if this generator has a huge period (larger than 2**(2**16)). |
|
637 |
*/ |
|
638 |
static final BigInteger HUGE_PERIOD = BigInteger.valueOf(-2); |
|
639 |
} |