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