author | jlaskey |
Thu, 14 Nov 2019 08:54:56 -0400 | |
branch | JDK-8193209-branch |
changeset 59080 | 1b314be4feb2 |
parent 57437 | f02ffcb61dce |
permissions | -rw-r--r-- |
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
1 |
/* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
4 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
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:
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:
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:
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:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
10 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
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:
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:
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:
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:
diff
changeset
|
15 |
* accompanied this code). |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
16 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
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:
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:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
20 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
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:
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:
diff
changeset
|
23 |
* questions. |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
24 |
*/ |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
25 |
|
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
26 |
/** |
59080 | 27 |
* Classes and interfaces that support the definition and use of "random generators", a term that |
28 |
* is meant to cover what have traditionally been called "random number generators" as well as |
|
29 |
* generators of other sorts of randomly chosen values, and also to cover not only deterministic |
|
30 |
* (pseudorandom) algorithms but also generators of values that use some "truly random" physical |
|
31 |
* source (perhaps making use of thermal noise, for example, or quantum-mechanical effects). |
|
32 |
* |
|
33 |
* The principal interface is {@link java.util.random.RandomGenerator}, which provides methods |
|
34 |
* for requesting individual values of type {@code int}, {@code long}, {@code float}, {@code double}, or {@code boolean} |
|
35 |
* chosen (pseudo)randomly from a uniform distribution; methods for requesting values of type {@code double} |
|
36 |
* chosen (pseudo)randomly from a normal distribution or from an exponential distribution; |
|
37 |
* and methods for creating streams of (pseudo)randomly chosen values of type {@code int}, {@code long}, or {@code double}. |
|
38 |
* These streams are spliterator-based, allowing for parallel processing of their elements. |
|
39 |
* |
|
40 |
* An important subsidiary interface is {@link java.util.random.RandomGenerator.StreamableGenerator}, |
|
41 |
* which provides methods for creating spliterator-based streams of {@code RandomGenerator} objects, |
|
42 |
* allowing for allowing for parallel processing of these objects using multiple threads. |
|
43 |
* Unlike {@link java.util.Random}, most implementations of {@code java.util.random.RandomGenerator} |
|
44 |
* are <i>not</i> thread-safe. The intent is that instances should not be shared among threads; |
|
45 |
* rather, each thread should have its own random generator(s) to use. The various pseudorandom algorithms |
|
46 |
* provided by this package are designed so that multiple instances will (with very high probability) behave as |
|
47 |
* if statistically independent. |
|
48 |
* |
|
49 |
* Historically, most pseudorandom generator algorithms have been based on some sort of |
|
50 |
* finite-state machine with a single, large cycle of states; when it is necessary to have |
|
51 |
* multiple threads use the same algorithm simultaneously, the usual technique is to arrange for |
|
52 |
* each thread to traverse a different region of the state cycle. These regions may be doled out |
|
53 |
* to threads by starting with a single initial state and then using a "jump function" that |
|
54 |
* travels a long distance around the cycle (perhaps 2<sup>64</sup> steps or more); the jump function is applied repeatedly |
|
55 |
* and sequentially, to identify widely spaced initial states for each thread's generator. This strategy is |
|
56 |
* supported by the interface {@link java.util.random.RandomGenerator.JumpableGenerator}. |
|
57 |
* Sometimes it is desirable to support two levels of jumping (by long distances and |
|
58 |
* by <i>really</i> long distances); this strategy is supported by the interface |
|
59 |
* {@link java.util.random.RandomGenerator.LeapableGenerator}. There is also an interface |
|
60 |
* {@link java.util.random.RandomGenerator.ArbitrarilyJumpableGenerator} for algorithms that |
|
61 |
* allow jumping along the state cycle by any user-specified distance. |
|
62 |
* In this package, implementations of these interfaces include |
|
63 |
* {@link java.util.random.Xoroshiro128PlusPlus}, |
|
64 |
* {@link java.util.random.Xoroshiro128StarStar}, |
|
65 |
* {@link java.util.random.Xoshiro256StarStar}, |
|
66 |
* and {@link java.util.random.MRG32K3A}. |
|
67 |
* |
|
68 |
* A more recent category of "splittable" pseudorandom generator algorithms uses a large family |
|
69 |
* of state cycles and makes some attempt to ensure that distinct instances use different state |
|
70 |
* cycles; but even if two instances "accidentally" use the same state cycle, they are highly |
|
71 |
* likely to traverse different regions parts of that shared state cycle. This strategy is |
|
72 |
* supported by the interface {@link java.util.random.RandomGenerator.SplittableGenerator}. |
|
73 |
* In this package, implementations of this interface include |
|
74 |
* {@link java.util.random.L32X64MixRandom}, |
|
75 |
* {@link java.util.random.L64X128MixRandom}, |
|
76 |
* {@link java.util.random.L64X128PlusPlusRandom}, |
|
77 |
* {@link java.util.random.L64X128StarStarMixRandom}, |
|
78 |
* {@link java.util.random.L64X256MixRandom}, |
|
79 |
* {@link java.util.random.L64X1024MixRandom}, |
|
80 |
* {@link java.util.random.L128X128MixRandom}, |
|
81 |
* {@link java.util.random.L128X128PlusPlusRandom}, |
|
82 |
* {@link java.util.random.L128X128StarStarMixRandom}, |
|
83 |
* {@link java.util.random.L128X256MixRandom}, |
|
84 |
* {@link java.util.random.L128X1024MixRandom}, |
|
85 |
* and {@link java.util.SplittableRandom}. |
|
86 |
* Generally speaking, among the "{@code LmmmXnnn}" generators, the state size of the generator is |
|
87 |
* {@code (mmm - 1 + nnn)} bits and the memory required for an instance is {@code (2 * mmm + nnn)} bits; |
|
88 |
* larger values of "{@code mmm}" imply a lower probability that two instances will traverse the |
|
89 |
* same state cycle; and larger values of "{@code nnn}" imply that the generator is equidistributed |
|
90 |
* in a larger number of dimensions. A class with "{@code Mix}" in its name uses a strong mixing |
|
91 |
* function with excellent avalanche characteristics; a class with "{@code StarStar}" or "{@code PlusPlus}" |
|
92 |
* in its name uses a weaker but faster mixing function. See the documentation for individual classes |
|
93 |
* for details about their specific characteristics. |
|
94 |
* |
|
95 |
* The class {@link java.util.random.RandomSupport} provides utility methods, constants, and |
|
96 |
* abstract classes frequently useful in the implementation of pseudorandom number generators |
|
97 |
* that satisfy the interface {@link RandomGenerator}. |
|
57437
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
98 |
* |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
99 |
* @since 14 |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
100 |
*/ |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
101 |
|
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
102 |
package java.util.random; |
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
103 |
|
f02ffcb61dce
Rename Rng.java to RandomNumberGenerator.java, clean up javadoc and misc code changes
jlaskey
parents:
diff
changeset
|
104 |