src/java.base/share/classes/java/util/random/ArbitrarilyJumpableRNG.java
author jlaskey
Thu, 27 Jun 2019 18:02:51 -0300
branchJDK-8193209-branch
changeset 57436 b0c958c0e6c6
parent 57388 src/java.base/share/classes/java/util/ArbitrarilyJumpableRng.java@b1e6bc96af3d
child 57437 f02ffcb61dce
permissions -rw-r--r--
Move random number generators to new folder.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57388
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
     1
/*
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
     4
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    10
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    15
 * accompanied this code).
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    16
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    20
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    23
 * questions.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    24
 */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    25
package java.util;
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    26
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    27
import java.util.stream.Stream;
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    28
import java.util.stream.StreamSupport;
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    29
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    30
/**
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    31
 * This interface is designed to provide a common protocol for objects
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    32
 * that generate sequences of pseudorandom numbers (or Boolean values)
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    33
 * and furthermore can easily <i>jump</i> to an arbitrarily specified
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    34
 * distant point in the state cycle.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    35
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    36
 * <p>Ideally, all {@code ArbitrarilyJumpableRng} objects produced by
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    37
 * iterative jumping from a single original {@code ArbtrarilyJumpableRng}
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    38
 * object are statistically independent of one another and
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    39
 * individually uniform, provided that they do not traverse
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    40
 * overlapping portions of the state cycle.  In practice, one must
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    41
 * settle for some approximation to independence and uniformity.  In
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    42
 * particular, a specific implementation may assume that each
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    43
 * generator in a stream produced by the {@code jumps} method is used
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    44
 * to produce a number of values no larger than the jump distance
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    45
 * specified.  Implementors are advised to use algorithms whose period
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    46
 * is at least 2<sup>127</sup>.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    47
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    48
 * <p>For many applications, it suffices to jump forward by a power of
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    49
 * two or some small multiple of a power of two, but this power of two
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    50
 * may not be representable as a {@code long} value.  To avoid the
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    51
 * use of {@code BigInteger} values as jump distances, {@code double}
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    52
 * values are used instead.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    53
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    54
 * <p>Methods are provided to perform a single jump operation and also
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    55
 * to produce a stream of generators produced from the original by
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    56
 * iterative copying and jumping of internal state.  A typical
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    57
 * strategy for a multithreaded application is to create a single
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    58
 * {@code ArbitrarilyJumpableRng} object, call its {@code jumps}
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    59
 * method exactly once, and then parcel out generators from the
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    60
 * resulting stream, one to each thread.  However, each generator
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    61
 * produced also has type {@code ArbitrarilyJumpableRng}; with care,
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    62
 * different jump distances can be used to traverse the entire
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    63
 * state cycle in various ways.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    64
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    65
 * <p>An implementation of the {@code ArbitrarilyJumpableRng} interface must
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    66
 * provide concrete definitions for the methods {@code nextInt()},
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    67
 * {@code nextLong}, {@code period()}, {@code copy()}, {@code jump(double)},
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    68
 * {@code defaultJumpDistance()}, and {@code defaultLeapDistance()}.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    69
 * Default implementations are provided for all other methods.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    70
 * Perhaps the most convenient
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    71
 * way to implement this interface is to extend the abstract class
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    72
 * {@link java.util.AbstractArbitrarilyJumpableRng}, which provides
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    73
 * spliterator-based implementations of the methods {@code ints}, {@code longs},
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    74
 * {@code doubles}, {@code rngs}, {@code jumps}, and {@code leaps}.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    75
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    76
 * <p>Objects that implement {@code java.util.ArbitrarilyJumpableRng}
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    77
 * are typically not cryptographically secure.  Consider instead using
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    78
 * {@link java.security.SecureRandom} to get a cryptographically
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    79
 * secure pseudo-random number generator for use by
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    80
 * security-sensitive applications.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    81
 *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    82
 * @author  Guy Steele
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    83
 * @since   1.9
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    84
 */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    85
public interface ArbitrarilyJumpableRng extends LeapableRng {
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    86
    /**
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    87
     * Returns a new generator whose internal state is an exact copy
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    88
     * of this generator (therefore their future behavior should be
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    89
     * identical if subjected to the same series of operations).
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    90
     *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    91
     * @return a new object that is a copy of this generator
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    92
     */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    93
    ArbitrarilyJumpableRng copy();
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    94
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    95
    /**
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    96
     * Alter the state of this pseudorandom number generator so as to
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    97
     * jump forward a distance equal to 2<sup>{@code logDistance}</sup>
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    98
     * within its state cycle.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
    99
     *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   100
     * @param logDistance the base-2 logarithm of the distance to jump
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   101
     *        forward within the state cycle
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   102
     * @throws IllegalArgumentException if {@code logDistance} is NaN
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   103
     *         or negative, or if 2<sup>{@code logDistance}</sup> is
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   104
     *         greater than the period of this generator
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   105
     */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   106
    void jumpPowerOfTwo(int logDistance);
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   107
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   108
    /**
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   109
     * Alter the state of this pseudorandom number generator so as to
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   110
     * jump forward a specified distance within its state cycle.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   111
     *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   112
     * @param distance the distance to jump forward within the state cycle
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   113
     * @throws IllegalArgumentException if {@code distance} is Nan,
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   114
     *         negative, or greater than the period of this generator
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   115
     */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   116
    void jump(double distance);
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   117
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   118
    /**
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   119
     * Alter the state of this pseudorandom number generator so as to
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   120
     * jump forward a large, fixed distance (typically 2<sup>64</sup>
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   121
     * or more) within its state cycle.  The distance used is that
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   122
     * returned by method {@code defaultJumpDistance()}.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   123
     */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   124
    default void jump() { jump(defaultJumpDistance()); }
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   125
    
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   126
    /**
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   127
     * Returns an effectively unlimited stream of new pseudorandom
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   128
     * number generators, each of which implements the {@code ArbitrarilyJumpableRng}
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   129
     * interface, produced by jumping copies of this generator
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   130
     * by different integer multiples of the specified jump distance.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   131
     *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   132
     * @implNote This method is implemented to be equivalent to
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   133
     * {@code jumps(Long.MAX_VALUE)}.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   134
     *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   135
     * @param distance a distance to jump forward within the state cycle
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   136
     * @return a stream of objects that implement the {@code Rng} interface
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   137
     */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   138
    default Stream<ArbitrarilyJumpableRng> jumps(double distance) {
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   139
	return Stream.generate(() -> copyAndJump(distance)).sequential();
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   140
    }
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   141
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   142
    /**
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   143
     * Returns a stream producing the given {@code streamSize} number of
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   144
     * new pseudorandom number generators, each of which implements the
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   145
     * {@code ArbitrarilyJumpableRng} interface, produced by jumping copies of this generator
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   146
     * by different integer multiples of the specified jump distance.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   147
     *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   148
     * @param streamSize the number of generators to generate
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   149
     * @param distance a distance to jump forward within the state cycle
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   150
     * @return a stream of objects that implement the {@code Rng} interface
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   151
     * @throws IllegalArgumentException if {@code streamSize} is
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   152
     *         less than zero
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   153
     */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   154
    default Stream<ArbitrarilyJumpableRng> jumps(long streamSize, double distance) {
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   155
        return jumps(distance).limit(streamSize);
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   156
    }
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   157
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   158
    /**
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   159
     * Alter the state of this pseudorandom number generator so as to
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   160
     * jump forward a very large, fixed distance (typically 2<sup>128</sup>
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   161
     * or more) within its state cycle.  The distance used is that
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   162
     * returned by method {@code defaultJLeapDistance()}.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   163
     */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   164
    default void leap() { jump(defaultLeapDistance()); }
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   165
     
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   166
    /**
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   167
     * Copy this generator, jump this generator forward, then return the copy.
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   168
     *
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   169
     * @param distance a distance to jump forward within the state cycle
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   170
     * @return a copy of this generator object before the jump occurred
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   171
     */
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   172
    default ArbitrarilyJumpableRng copyAndJump(double distance) {
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   173
	ArbitrarilyJumpableRng result = copy();
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   174
	jump(distance);
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   175
	return result;
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   176
    }
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   177
b1e6bc96af3d Initial commit of new RNG code from GLS
briangoetz
parents:
diff changeset
   178
}