RandomSource.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.rng.simple;

  18. import java.util.stream.DoubleStream;
  19. import java.util.stream.IntStream;
  20. import java.util.stream.LongStream;
  21. import org.apache.commons.rng.UniformRandomProvider;
  22. import org.apache.commons.rng.RestorableUniformRandomProvider;
  23. import org.apache.commons.rng.simple.internal.ProviderBuilder;
  24. import org.apache.commons.rng.simple.internal.SeedFactory;

  25. /**
  26.  * This class provides the API for creating generators of random numbers.
  27.  *
  28.  * <p>Usage examples:</p>
  29.  * <pre><code>
  30.  *  UniformRandomProvider rng = RandomSource.XO_RO_SHI_RO_128_PP.create();
  31.  * </code></pre>
  32.  * or
  33.  * <pre><code>
  34.  *  final int[] seed = new int[] { 196, 9, 0, 226 };
  35.  *  UniformRandomProvider rng = RandomSource.XO_RO_SHI_RO_128_PP.create(seed);
  36.  * </code></pre>
  37.  * or
  38.  * <pre><code>
  39.  *  final int[] seed = RandomSource.createIntArray(256);
  40.  *  UniformRandomProvider rng = RandomSource.XO_RO_SHI_RO_128_PP.create(seed);
  41.  * </code></pre>
  42.  * where the enum value is the identifier of the generator's concrete
  43.  * implementation, and the argument to method {@code create} is the
  44.  * (optional) seed.
  45.  *
  46.  * <p>
  47.  * In the first form, a random seed will be {@link SeedFactory generated
  48.  * automatically}; in the second form, a fixed seed is used; a random seed
  49.  * is explicitly generated in the third form.
  50.  * </p>
  51.  *
  52.  * <h2>Seeding</h2>
  53.  * <p>
  54.  * Seeding is the procedure by which a value (or set of values) is
  55.  * used to <i>initialize</i> a generator instance.
  56.  * The requirement that a given seed will always result in the same
  57.  * internal state allows to create different instances of a generator
  58.  * that will produce the same sequence of pseudo-random numbers.
  59.  * </p>
  60.  *
  61.  * <p>
  62.  * The type of data used as a seed depends on the concrete implementation
  63.  * as some types may not provide enough information to fully initialize
  64.  * the generator's internal state.
  65.  * <br>
  66.  * The reference algorithm's seeding procedure (if provided) operates
  67.  * on a value of a (single) <i>native</i> type:
  68.  * Each concrete implementation's constructor creates an instance using
  69.  * the native type whose information contents is used to set the
  70.  * internal state.
  71.  * <br>
  72.  * When the seed value passed by the caller is of the native type, it is
  73.  * expected that the sequences produced will be identical to those
  74.  * produced by other implementations of the same reference algorithm.
  75.  * <br>
  76.  * However, when the seed value passed by the caller is not of the native
  77.  * type, a transformation is performed by this library and the resulting
  78.  * native type value will <i>not</i> contain more information than the
  79.  * original seed value.
  80.  * If the algorithm's native type is "simpler" than the type passed by
  81.  * the caller, then some (unused) information will even be lost.
  82.  * <br>
  83.  * The transformation from non-native to native seed type is arbitrary,
  84.  * as long as it does not reduce the amount of information required by
  85.  * the algorithm to initialize its state.
  86.  * The consequence of the transformation is that sequences produced
  87.  * by this library may <i>not</i> be the same as the sequences produced
  88.  * by other implementations of the same algorithm!
  89.  * </p>
  90.  *
  91.  * <p>
  92.  * For each algorithm, the Javadoc mentions the "ideal" size of the seed,
  93.  * meaning the number of {@code int} or {@code long} values that is neither
  94.  * too large (i.e. some of the seed is useless) or too small (i.e. an
  95.  * internal procedure will fill the state with redundant information
  96.  * computed from the given seed).
  97.  * </p>
  98.  *
  99.  * <p>
  100.  * Note that some algorithms are inherently sensitive to having too low
  101.  * diversity in their initial state.
  102.  * For example, it is often a bad idea to use a seed that is mostly
  103.  * composed of zeroes, or of repeated values.
  104.  * </p>
  105.  *
  106.  * <p>
  107.  * This class provides methods to generate random seeds (single values
  108.  * or arrays of values, of {@code int} or {@code long} types) that can
  109.  * be passed to the {@link RandomSource#create(Object,Object[])
  110.  * generator's factory method}.
  111.  * </p>
  112.  * <p>
  113.  * Although the seed-generating methods defined in this class will likely
  114.  * return different values each time they are called, there is no guarantee:
  115.  * </p>
  116.  * <ul>
  117.  *  <li>
  118.  *   In any sub-sequence, it is <a href="https://en.wikipedia.org/wiki/Birthday_problem">
  119.  *   expected</a> that the same numbers can occur, with a probability getting
  120.  *   higher as the range of allowed values is smaller and the sequence becomes
  121.  *   longer.
  122.  *  </li>
  123.  *  <li>
  124.  *   It possible that the resulting "seed" will not be <i>good</i> (i.e.
  125.  *   it will not generate a sufficiently uniformly random sequence for the
  126.  *   intended purpose), even if the generator is good!
  127.  *   The only way to ensure that the selected seed will make the generator
  128.  *   produce a good sequence is to submit that sequence to a series of
  129.  *   stringent tests, as provided by tools such as
  130.  *   <a href="http://www.phy.duke.edu/~rgb/General/dieharder.php">dieharder</a>
  131.  *   or <a href="http://simul.iro.umontreal.ca/testu01/tu01.html">TestU01</a>.
  132.  *  </li>
  133.  * </ul>
  134.  *
  135.  * <p>
  136.  * <b>Note:</b>
  137.  * Seeding is not equivalent to restoring the internal state of an
  138.  * <i>already initialized</i> generator.
  139.  * Indeed, generators can have a state that is more complex than the
  140.  * seed, and seeding is thus a transformation (from seed to state).
  141.  * Implementations do not provide the inverse transformation (from
  142.  * state to seed), hence it is not generally possible to know the seed
  143.  * that would initialize a new generator instance to the current state
  144.  * of another instance.
  145.  * Reseeding is also inefficient if the purpose is to continue the
  146.  * same sequence where another instance left off, as it would require
  147.  * to "replay" all the calls performed by that other instance (and it
  148.  * would require to know the number of calls to the primary source of
  149.  * randomness, which is also not usually accessible).
  150.  * </p>
  151.  *
  152.  * <h2>Parallel applications</h2>
  153.  * <p>
  154.  * For parallel applications, some implementations have provision for producing
  155.  * non-overlapping sequences by copying the generator and then advancing a large number
  156.  * of steps in the generator sequence. Repeated jumps can create a series of
  157.  * child generators that will output non-overlapping sequences over a specified number
  158.  * of outputs. These implementations are identified using the {@link #isJumpable()}
  159.  * and {@link #isLongJumpable()} methods.
  160.  * </p>
  161.  * <pre><code>
  162.  *  RandomSource source = RandomSource.XO_RO_SHI_RO_128_SS; // Known to be jumpable.
  163.  *
  164.  *  JumpableUniformRandomProvider jumpable = (JumpableUniformRandomProvider) source.create();
  165.  *
  166.  *  // For use in parallel
  167.  *  UniformRandomProvider[] rngs = new UniformRandomProvider[10];
  168.  *  for (int i = 0; i &lt; rngs.length; i++) {
  169.  *      rngs[i] = jumpable.jump();
  170.  *  }
  171.  * </code></pre>
  172.  * <p>
  173.  * For implementations that have no provision for producing non-overlapping
  174.  * sequences, a possible workaround is that each thread uses
  175.  * a generator of a different type (see {@link #TWO_CMRES_SELECT}).
  176.  * </p>
  177.  *
  178.  * @since 1.0
  179.  */
  180. public enum RandomSource {
  181.     /**
  182.      * Source of randomness is {@link org.apache.commons.rng.core.source32.JDKRandom}.
  183.      * <ul>
  184.      *  <li>Native seed type: {@code Long}.</li>
  185.      * </ul>
  186.      */
  187.     JDK(ProviderBuilder.RandomSourceInternal.JDK),
  188.     /**
  189.      * Source of randomness is {@link org.apache.commons.rng.core.source32.Well512a}.
  190.      * <ul>
  191.      *  <li>Native seed type: {@code int[]}.</li>
  192.      *  <li>Native seed size: 16.</li>
  193.      * </ul>
  194.      */
  195.     WELL_512_A(ProviderBuilder.RandomSourceInternal.WELL_512_A),
  196.     /**
  197.      * Source of randomness is {@link org.apache.commons.rng.core.source32.Well1024a}.
  198.      * <ul>
  199.      *  <li>Native seed type: {@code int[]}.</li>
  200.      *  <li>Native seed size: 32.</li>
  201.      * </ul>
  202.      */
  203.     WELL_1024_A(ProviderBuilder.RandomSourceInternal.WELL_1024_A),
  204.     /**
  205.      * Source of randomness is {@link org.apache.commons.rng.core.source32.Well19937a}.
  206.      * <ul>
  207.      *  <li>Native seed type: {@code int[]}.</li>
  208.      *  <li>Native seed size: 624.</li>
  209.      * </ul>
  210.      */
  211.     WELL_19937_A(ProviderBuilder.RandomSourceInternal.WELL_19937_A),
  212.     /**
  213.      * Source of randomness is {@link org.apache.commons.rng.core.source32.Well19937c}.
  214.      * <ul>
  215.      *  <li>Native seed type: {@code int[]}.</li>
  216.      *  <li>Native seed size: 624.</li>
  217.      * </ul>
  218.      */
  219.     WELL_19937_C(ProviderBuilder.RandomSourceInternal.WELL_19937_C),
  220.     /**
  221.      * Source of randomness is {@link org.apache.commons.rng.core.source32.Well44497a}.
  222.      * <ul>
  223.      *  <li>Native seed type: {@code int[]}.</li>
  224.      *  <li>Native seed size: 1391.</li>
  225.      * </ul>
  226.      */
  227.     WELL_44497_A(ProviderBuilder.RandomSourceInternal.WELL_44497_A),
  228.     /**
  229.      * Source of randomness is {@link org.apache.commons.rng.core.source32.Well44497b}.
  230.      * <ul>
  231.      *  <li>Native seed type: {@code int[]}.</li>
  232.      *  <li>Native seed size: 1391.</li>
  233.      * </ul>
  234.      */
  235.     WELL_44497_B(ProviderBuilder.RandomSourceInternal.WELL_44497_B),
  236.     /**
  237.      * Source of randomness is {@link org.apache.commons.rng.core.source32.MersenneTwister}.
  238.      * <ul>
  239.      *  <li>Native seed type: {@code int[]}.</li>
  240.      *  <li>Native seed size: 624.</li>
  241.      * </ul>
  242.      */
  243.     MT(ProviderBuilder.RandomSourceInternal.MT),
  244.     /**
  245.      * Source of randomness is {@link org.apache.commons.rng.core.source32.ISAACRandom}.
  246.      * <ul>
  247.      *  <li>Native seed type: {@code int[]}.</li>
  248.      *  <li>Native seed size: 256.</li>
  249.      * </ul>
  250.      */
  251.     ISAAC(ProviderBuilder.RandomSourceInternal.ISAAC),
  252.     /**
  253.      * Source of randomness is {@link org.apache.commons.rng.core.source64.SplitMix64}.
  254.      * <ul>
  255.      *  <li>Native seed type: {@code Long}.</li>
  256.      * </ul>
  257.      */
  258.     SPLIT_MIX_64(ProviderBuilder.RandomSourceInternal.SPLIT_MIX_64),
  259.     /**
  260.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XorShift1024Star}.
  261.      * <ul>
  262.      *  <li>Native seed type: {@code long[]}.</li>
  263.      *  <li>Native seed size: 16.</li>
  264.      * </ul>
  265.      *
  266.      * @deprecated Since 1.3, where it is recommended to use {@code XOR_SHIFT_1024_S_PHI}
  267.      * instead due to its slightly better (more uniform) output. {@code XOR_SHIFT_1024_S}
  268.      * is still quite usable but both are variants of the same algorithm and maintain their
  269.      * internal state identically. Their outputs are correlated and the two should not be
  270.      * used together when independent sequences are assumed.
  271.      */
  272.     @Deprecated
  273.     XOR_SHIFT_1024_S(ProviderBuilder.RandomSourceInternal.XOR_SHIFT_1024_S),
  274.     /**
  275.      * Source of randomness is {@link org.apache.commons.rng.core.source64.TwoCmres}.
  276.      * This generator is equivalent to {@link #TWO_CMRES_SELECT} with the choice of the
  277.      * pair {@code (0, 1)} for the two subcycle generators.
  278.      * <ul>
  279.      *  <li>Native seed type: {@code Integer}.</li>
  280.      * </ul>
  281.      */
  282.     TWO_CMRES(ProviderBuilder.RandomSourceInternal.TWO_CMRES),
  283.     /**
  284.      * Source of randomness is {@link org.apache.commons.rng.core.source64.TwoCmres},
  285.      * with explicit selection of the two subcycle generators.
  286.      * The selection of the subcycle generator is by passing its index in the internal
  287.      * table, a value between 0 (included) and 13 (included).
  288.      * The two indices must be different.
  289.      * Different choices of an ordered pair of indices create independent generators.
  290.      * <ul>
  291.      *  <li>Native seed type: {@code Integer}.</li>
  292.      * </ul>
  293.      */
  294.     TWO_CMRES_SELECT(ProviderBuilder.RandomSourceInternal.TWO_CMRES_SELECT),
  295.     /**
  296.      * Source of randomness is {@link org.apache.commons.rng.core.source64.MersenneTwister64}.
  297.      * <ul>
  298.      *  <li>Native seed type: {@code long[]}.</li>
  299.      *  <li>Native seed size: 312.</li>
  300.      * </ul>
  301.      */
  302.     MT_64(ProviderBuilder.RandomSourceInternal.MT_64),
  303.     /**
  304.      * Source of randomness is {@link org.apache.commons.rng.core.source32.MultiplyWithCarry256}.
  305.      * <ul>
  306.      *  <li>Native seed type: {@code int[]}.</li>
  307.      *  <li>Native seed size: 257.</li>
  308.      * </ul>
  309.      */
  310.     MWC_256(ProviderBuilder.RandomSourceInternal.MWC_256),
  311.     /**
  312.      * Source of randomness is {@link org.apache.commons.rng.core.source32.KISSRandom}.
  313.      * <ul>
  314.      *  <li>Native seed type: {@code int[]}.</li>
  315.      *  <li>Native seed size: 4.</li>
  316.      * </ul>
  317.      */
  318.     KISS(ProviderBuilder.RandomSourceInternal.KISS),
  319.     /**
  320.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XorShift1024StarPhi}.
  321.      * <ul>
  322.      *  <li>Native seed type: {@code long[]}.</li>
  323.      *  <li>Native seed size: 16.</li>
  324.      * </ul>
  325.      * @since 1.3
  326.      */
  327.     XOR_SHIFT_1024_S_PHI(ProviderBuilder.RandomSourceInternal.XOR_SHIFT_1024_S_PHI),
  328.     /**
  329.      * Source of randomness is {@link org.apache.commons.rng.core.source32.XoRoShiRo64Star}.
  330.      * <ul>
  331.      *  <li>Native seed type: {@code int[]}.</li>
  332.      *  <li>Native seed size: 2.</li>
  333.      * </ul>
  334.      * @since 1.3
  335.      */
  336.     XO_RO_SHI_RO_64_S(ProviderBuilder.RandomSourceInternal.XO_RO_SHI_RO_64_S),
  337.     /**
  338.      * Source of randomness is {@link org.apache.commons.rng.core.source32.XoRoShiRo64StarStar}.
  339.      * <ul>
  340.      *  <li>Native seed type: {@code int[]}.</li>
  341.      *  <li>Native seed size: 2.</li>
  342.      * </ul>
  343.      * @since 1.3
  344.      */
  345.     XO_RO_SHI_RO_64_SS(ProviderBuilder.RandomSourceInternal.XO_RO_SHI_RO_64_SS),
  346.     /**
  347.      * Source of randomness is {@link org.apache.commons.rng.core.source32.XoShiRo128Plus}.
  348.      * <ul>
  349.      *  <li>Native seed type: {@code int[]}.</li>
  350.      *  <li>Native seed size: 4.</li>
  351.      * </ul>
  352.      * @since 1.3
  353.      */
  354.     XO_SHI_RO_128_PLUS(ProviderBuilder.RandomSourceInternal.XO_SHI_RO_128_PLUS),
  355.     /**
  356.      * Source of randomness is {@link org.apache.commons.rng.core.source32.XoShiRo128StarStar}.
  357.      * <ul>
  358.      *  <li>Native seed type: {@code int[]}.</li>
  359.      *  <li>Native seed size: 4.</li>
  360.      * </ul>
  361.      * @since 1.3
  362.      */
  363.     XO_SHI_RO_128_SS(ProviderBuilder.RandomSourceInternal.XO_SHI_RO_128_SS),
  364.     /**
  365.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoRoShiRo128Plus}.
  366.      * <ul>
  367.      *  <li>Native seed type: {@code long[]}.</li>
  368.      *  <li>Native seed size: 2.</li>
  369.      * </ul>
  370.      * @since 1.3
  371.      */
  372.     XO_RO_SHI_RO_128_PLUS(ProviderBuilder.RandomSourceInternal.XO_RO_SHI_RO_128_PLUS),
  373.     /**
  374.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoRoShiRo128StarStar}.
  375.      * <ul>
  376.      *  <li>Native seed type: {@code long[]}.</li>
  377.      *  <li>Native seed size: 2.</li>
  378.      * </ul>
  379.      * @since 1.3
  380.      */
  381.     XO_RO_SHI_RO_128_SS(ProviderBuilder.RandomSourceInternal.XO_RO_SHI_RO_128_SS),
  382.     /**
  383.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoShiRo256Plus}.
  384.      * <ul>
  385.      *  <li>Native seed type: {@code long[]}.</li>
  386.      *  <li>Native seed size: 4.</li>
  387.      * </ul>
  388.      * @since 1.3
  389.      */
  390.     XO_SHI_RO_256_PLUS(ProviderBuilder.RandomSourceInternal.XO_SHI_RO_256_PLUS),
  391.     /**
  392.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoShiRo256StarStar}.
  393.      * <ul>
  394.      *  <li>Native seed type: {@code long[]}.</li>
  395.      *  <li>Native seed size: 4.</li>
  396.      * </ul>
  397.      * @since 1.3
  398.      */
  399.     XO_SHI_RO_256_SS(ProviderBuilder.RandomSourceInternal.XO_SHI_RO_256_SS),
  400.     /**
  401.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoShiRo512Plus}.
  402.      * <ul>
  403.      *  <li>Native seed type: {@code long[]}.</li>
  404.      *  <li>Native seed size: 8.</li>
  405.      * </ul>
  406.      * @since 1.3
  407.      */
  408.     XO_SHI_RO_512_PLUS(ProviderBuilder.RandomSourceInternal.XO_SHI_RO_512_PLUS),
  409.     /**
  410.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoShiRo512StarStar}.
  411.      * <ul>
  412.      *  <li>Native seed type: {@code long[]}.</li>
  413.      *  <li>Native seed size: 8.</li>
  414.      * </ul>
  415.      * @since 1.3
  416.      */
  417.     XO_SHI_RO_512_SS(ProviderBuilder.RandomSourceInternal.XO_SHI_RO_512_SS),
  418.     /**
  419.      * Source of randomness is {@link org.apache.commons.rng.core.source32.PcgXshRr32}.
  420.      * <ul>
  421.      *  <li>Native seed type: {@code long[]}.</li>
  422.      *  <li>Native seed size: 2.</li>
  423.      * </ul>
  424.      * @since 1.3
  425.      */
  426.     PCG_XSH_RR_32(ProviderBuilder.RandomSourceInternal.PCG_XSH_RR_32),
  427.     /**
  428.      * Source of randomness is {@link org.apache.commons.rng.core.source32.PcgXshRs32}.
  429.      * <ul>
  430.      *  <li>Native seed type: {@code long[]}.</li>
  431.      *  <li>Native seed size: 2.</li>
  432.      * </ul>
  433.      * @since 1.3
  434.      */
  435.     PCG_XSH_RS_32(ProviderBuilder.RandomSourceInternal.PCG_XSH_RS_32),
  436.     /**
  437.      * Source of randomness is {@link org.apache.commons.rng.core.source64.PcgRxsMXs64}.
  438.      * <ul>
  439.      *  <li>Native seed type: {@code long[]}.</li>
  440.      *  <li>Native seed size: 2.</li>
  441.      * </ul>
  442.      * @since 1.3
  443.      */
  444.     PCG_RXS_M_XS_64(ProviderBuilder.RandomSourceInternal.PCG_RXS_M_XS_64),
  445.     /**
  446.      * Source of randomness is {@link org.apache.commons.rng.core.source32.PcgMcgXshRr32}.
  447.      * <ul>
  448.      *  <li>Native seed type: {@code Long}.</li>
  449.      * </ul>
  450.      * @since 1.3
  451.      */
  452.     PCG_MCG_XSH_RR_32(ProviderBuilder.RandomSourceInternal.PCG_MCG_XSH_RR_32),
  453.     /**
  454.      * Source of randomness is {@link org.apache.commons.rng.core.source32.PcgMcgXshRs32}.
  455.      * <ul>
  456.      *  <li>Native seed type: {@code Long}.</li>
  457.      * </ul>
  458.      * @since 1.3
  459.      */
  460.     PCG_MCG_XSH_RS_32(ProviderBuilder.RandomSourceInternal.PCG_MCG_XSH_RS_32),
  461.     /**
  462.      * Source of randomness is {@link org.apache.commons.rng.core.source32.MiddleSquareWeylSequence}.
  463.      * <ul>
  464.      *  <li>Native seed type: {@code long[]}.</li>
  465.      *  <li>Native seed size: 3.</li>
  466.      * </ul>
  467.      * @since 1.3
  468.      */
  469.     MSWS(ProviderBuilder.RandomSourceInternal.MSWS),
  470.     /**
  471.      * Source of randomness is {@link org.apache.commons.rng.core.source32.DotyHumphreySmallFastCounting32}.
  472.      * <ul>
  473.      *  <li>Native seed type: {@code int[]}.</li>
  474.      *  <li>Native seed size: 3.</li>
  475.      * </ul>
  476.      * @since 1.3
  477.      */
  478.     SFC_32(ProviderBuilder.RandomSourceInternal.SFC_32),
  479.     /**
  480.      * Source of randomness is {@link org.apache.commons.rng.core.source64.DotyHumphreySmallFastCounting64}.
  481.      * <ul>
  482.      *  <li>Native seed type: {@code long[]}.</li>
  483.      *  <li>Native seed size: 3.</li>
  484.      * </ul>
  485.      * @since 1.3
  486.      */
  487.     SFC_64(ProviderBuilder.RandomSourceInternal.SFC_64),
  488.     /**
  489.      * Source of randomness is {@link org.apache.commons.rng.core.source32.JenkinsSmallFast32}.
  490.      * <ul>
  491.      *  <li>Native seed type: {@code Integer}.</li>
  492.      * </ul>
  493.      * @since 1.3
  494.      */
  495.     JSF_32(ProviderBuilder.RandomSourceInternal.JSF_32),
  496.     /**
  497.      * Source of randomness is {@link org.apache.commons.rng.core.source64.JenkinsSmallFast64}.
  498.      * <ul>
  499.      *  <li>Native seed type: {@code Long}.</li>
  500.      * </ul>
  501.      * @since 1.3
  502.      */
  503.     JSF_64(ProviderBuilder.RandomSourceInternal.JSF_64),
  504.     /**
  505.      * Source of randomness is {@link org.apache.commons.rng.core.source32.XoShiRo128PlusPlus}.
  506.      * <ul>
  507.      *  <li>Native seed type: {@code int[]}.</li>
  508.      *  <li>Native seed size: 4.</li>
  509.      * </ul>
  510.      * @since 1.3
  511.      */
  512.     XO_SHI_RO_128_PP(ProviderBuilder.RandomSourceInternal.XO_SHI_RO_128_PP),
  513.     /**
  514.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoRoShiRo128PlusPlus}.
  515.      * <ul>
  516.      *  <li>Native seed type: {@code long[]}.</li>
  517.      *  <li>Native seed size: 2.</li>
  518.      * </ul>
  519.      * @since 1.3
  520.      */
  521.     XO_RO_SHI_RO_128_PP(ProviderBuilder.RandomSourceInternal.XO_RO_SHI_RO_128_PP),
  522.     /**
  523.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoShiRo256PlusPlus}.
  524.      * <ul>
  525.      *  <li>Native seed type: {@code long[]}.</li>
  526.      *  <li>Native seed size: 4.</li>
  527.      * </ul>
  528.      * @since 1.3
  529.      */
  530.     XO_SHI_RO_256_PP(ProviderBuilder.RandomSourceInternal.XO_SHI_RO_256_PP),
  531.     /**
  532.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoShiRo512PlusPlus}.
  533.      * <ul>
  534.      *  <li>Native seed type: {@code long[]}.</li>
  535.      *  <li>Native seed size: 8.</li>
  536.      * </ul>
  537.      * @since 1.3
  538.      */
  539.     XO_SHI_RO_512_PP(ProviderBuilder.RandomSourceInternal.XO_SHI_RO_512_PP),
  540.     /**
  541.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoRoShiRo1024PlusPlus}.
  542.      * <ul>
  543.      *  <li>Native seed type: {@code long[]}.</li>
  544.      *  <li>Native seed size: 16.</li>
  545.      * </ul>
  546.      * @since 1.3
  547.      */
  548.     XO_RO_SHI_RO_1024_PP(ProviderBuilder.RandomSourceInternal.XO_RO_SHI_RO_1024_PP),
  549.     /**
  550.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoRoShiRo1024Star}.
  551.      * <ul>
  552.      *  <li>Native seed type: {@code long[]}.</li>
  553.      *  <li>Native seed size: 16.</li>
  554.      * </ul>
  555.      * @since 1.3
  556.      */
  557.     XO_RO_SHI_RO_1024_S(ProviderBuilder.RandomSourceInternal.XO_RO_SHI_RO_1024_S),
  558.     /**
  559.      * Source of randomness is {@link org.apache.commons.rng.core.source64.XoRoShiRo1024StarStar}.
  560.      * <ul>
  561.      *  <li>Native seed type: {@code long[]}.</li>
  562.      *  <li>Native seed size: 16.</li>
  563.      * </ul>
  564.      * @since 1.3
  565.      */
  566.     XO_RO_SHI_RO_1024_SS(ProviderBuilder.RandomSourceInternal.XO_RO_SHI_RO_1024_SS),
  567.     /**
  568.      * Source of randomness is {@link org.apache.commons.rng.core.source32.PcgXshRr32}.
  569.      * <ul>
  570.      *  <li>Native seed type: {@code Long}.</li>
  571.      * </ul>
  572.      * @since 1.4
  573.      */
  574.     PCG_XSH_RR_32_OS(ProviderBuilder.RandomSourceInternal.PCG_XSH_RR_32_OS),
  575.     /**
  576.      * Source of randomness is {@link org.apache.commons.rng.core.source32.PcgXshRs32}.
  577.      * <ul>
  578.      *  <li>Native seed type: {@code Long}.</li>
  579.      * </ul>
  580.      * @since 1.4
  581.      */
  582.     PCG_XSH_RS_32_OS(ProviderBuilder.RandomSourceInternal.PCG_XSH_RS_32_OS),
  583.     /**
  584.      * Source of randomness is {@link org.apache.commons.rng.core.source64.PcgRxsMXs64}.
  585.      * <ul>
  586.      *  <li>Native seed type: {@code Long}.</li>
  587.      * </ul>
  588.      * @since 1.4
  589.      */
  590.     PCG_RXS_M_XS_64_OS(ProviderBuilder.RandomSourceInternal.PCG_RXS_M_XS_64_OS),
  591.     /**
  592.      * Source of randomness is {@link org.apache.commons.rng.core.source64.L64X128StarStar}.
  593.      * <ul>
  594.      *  <li>Native seed type: {@code long[]}.</li>
  595.      *  <li>Native seed size: 4.</li>
  596.      * </ul>
  597.      * @since 1.5
  598.      */
  599.     L64_X128_SS(ProviderBuilder.RandomSourceInternal.L64_X128_SS),
  600.     /**
  601.      * Source of randomness is {@link org.apache.commons.rng.core.source64.L64X128Mix}.
  602.      * <ul>
  603.      *  <li>Native seed type: {@code long[]}.</li>
  604.      *  <li>Native seed size: 4.</li>
  605.      * </ul>
  606.      * @since 1.5
  607.      */
  608.     L64_X128_MIX(ProviderBuilder.RandomSourceInternal.L64_X128_MIX),
  609.     /**
  610.      * Source of randomness is {@link org.apache.commons.rng.core.source64.L64X256Mix}.
  611.      * <ul>
  612.      *  <li>Native seed type: {@code long[]}.</li>
  613.      *  <li>Native seed size: 6.</li>
  614.      * </ul>
  615.      * @since 1.5
  616.      */
  617.     L64_X256_MIX(ProviderBuilder.RandomSourceInternal.L64_X256_MIX),
  618.     /**
  619.      * Source of randomness is {@link org.apache.commons.rng.core.source64.L64X1024Mix}.
  620.      * <ul>
  621.      *  <li>Native seed type: {@code long[]}.</li>
  622.      *  <li>Native seed size: 18.</li>
  623.      * </ul>
  624.      * @since 1.5
  625.      */
  626.     L64_X1024_MIX(ProviderBuilder.RandomSourceInternal.L64_X1024_MIX),
  627.     /**
  628.      * Source of randomness is {@link org.apache.commons.rng.core.source64.L128X128Mix}.
  629.      * <ul>
  630.      *  <li>Native seed type: {@code long[]}.</li>
  631.      *  <li>Native seed size: 6.</li>
  632.      * </ul>
  633.      * @since 1.5
  634.      */
  635.     L128_X128_MIX(ProviderBuilder.RandomSourceInternal.L128_X128_MIX),
  636.     /**
  637.      * Source of randomness is {@link org.apache.commons.rng.core.source64.L128X256Mix}.
  638.      * <ul>
  639.      *  <li>Native seed type: {@code long[]}.</li>
  640.      *  <li>Native seed size: 8.</li>
  641.      * </ul>
  642.      * @since 1.5
  643.      */
  644.     L128_X256_MIX(ProviderBuilder.RandomSourceInternal.L128_X256_MIX),
  645.     /**
  646.      * Source of randomness is {@link org.apache.commons.rng.core.source64.L128X1024Mix}.
  647.      * <ul>
  648.      *  <li>Native seed type: {@code long[]}.</li>
  649.      *  <li>Native seed size: 20.</li>
  650.      * </ul>
  651.      * @since 1.5
  652.      */
  653.     L128_X1024_MIX(ProviderBuilder.RandomSourceInternal.L128_X1024_MIX),
  654.     /**
  655.      * Source of randomness is {@link org.apache.commons.rng.core.source32.L32X64Mix}.
  656.      * <ul>
  657.      *  <li>Native seed type: {@code int[]}.</li>
  658.      *  <li>Native seed size: 4.</li>
  659.      * </ul>
  660.      * @since 1.5
  661.      */
  662.     L32_X64_MIX(ProviderBuilder.RandomSourceInternal.L32_X64_MIX);

  663.     /** Internal identifier. */
  664.     private final ProviderBuilder.RandomSourceInternal internalIdentifier;

  665.     /**
  666.      * @param id Internal identifier.
  667.      */
  668.     RandomSource(ProviderBuilder.RandomSourceInternal id) {
  669.         internalIdentifier = id;
  670.     }

  671.     /**
  672.      * @return the internal identifier.
  673.      */
  674.     ProviderBuilder.RandomSourceInternal getInternalIdentifier() {
  675.         return internalIdentifier;
  676.     }

  677.     /**
  678.      * Checks whether the type of given {@code seed} is the native type
  679.      * of the implementation.
  680.      *
  681.      * @param seed Seed value.
  682.      * @return {@code true} if the type of {@code seed} is the native
  683.      * type for this RNG source.
  684.      */
  685.     public boolean isNativeSeed(Object seed) {
  686.         return internalIdentifier.isNativeSeed(seed);
  687.     }

  688.     /**
  689.      * Creates a seed suitable for the implementing class represented by this random source.
  690.      *
  691.      * <p>The seed will be created as if passing a {@code null} seed to the method
  692.      * {@link #create(Object, Object...)}. It will satisfy the seed size and any
  693.      * other seed requirements for the implementing class. The seed is converted from the native
  694.      * type to a byte representation.</p>
  695.      *
  696.      * <p>Usage example:</p>
  697.      * <pre><code>
  698.      *  RandomSource source = ...;
  699.      *  byte[] seed = source.createSeed();
  700.      *  UniformRandomProvider rng = source.create(seed);
  701.      * </code></pre>
  702.      *
  703.      * @return the seed
  704.      * @since 1.3
  705.      */
  706.     public byte[] createSeed() {
  707.         return internalIdentifier.createSeedBytes();
  708.     }

  709.     /**
  710.      * Creates a seed suitable for the implementing class represented by this random source
  711.      * using the supplied source of randomness.
  712.      *
  713.      * <p>The seed will satisfy the seed size and any other seed requirements for the
  714.      * implementing class.</p>
  715.      *
  716.      * <p>Usage example:</p>
  717.      * <pre><code>
  718.      *  RandomSource source = ...;
  719.      *  UniformRandomProvider seedRng = new JDKRandomWrapper(new SecureRandom());
  720.      *  byte[] seed = source.createSeed(seedRng);
  721.      *  UniformRandomProvider rng = source.create(seed);
  722.      * </code></pre>
  723.      *
  724.      * @param rng Source of randomness.
  725.      * @return the seed
  726.      * @since 1.3
  727.      */
  728.     public byte[] createSeed(UniformRandomProvider rng) {
  729.         return internalIdentifier.createSeedBytes(rng);
  730.     }

  731.     /**
  732.      * Checks whether the implementing class represented by this random source
  733.      * supports the {@link org.apache.commons.rng.JumpableUniformRandomProvider
  734.      * JumpableUniformRandomProvider} interface. If {@code true} the instance returned
  735.      * by {@link #create(RandomSource)} may be cast to the interface; otherwise a class
  736.      * cast exception will occur.
  737.      *
  738.      * <p>Usage example:</p>
  739.      * <pre><code>
  740.      *  RandomSource source = ...;
  741.      *  if (source.isJumpable()) {
  742.      *      JumpableUniformRandomProvider rng =
  743.      *          (JumpableUniformRandomProvider) source.create();
  744.      *  }
  745.      * </code></pre>
  746.      *
  747.      * @return {@code true} if jumpable
  748.      * @since 1.3
  749.      */
  750.     public boolean isJumpable() {
  751.         return isAssignableTo(org.apache.commons.rng.JumpableUniformRandomProvider.class);
  752.     }

  753.     /**
  754.      * Checks whether the implementing class represented by this random source
  755.      * supports the {@link org.apache.commons.rng.LongJumpableUniformRandomProvider
  756.      * LongJumpableUniformRandomProvider} interface. If {@code true} the instance returned
  757.      * by {@link #create(RandomSource)} may be cast to the interface; otherwise a class
  758.      * cast exception will occur.
  759.      *
  760.      * <p>Usage example:</p>
  761.      * <pre><code>
  762.      *  RandomSource source = ...;
  763.      *  if (source.isJumpable()) {
  764.      *      LongJumpableUniformRandomProvider rng =
  765.      *          (LongJumpableUniformRandomProvider) source.create();
  766.      *  }
  767.      * </code></pre>
  768.      *
  769.      * @return {@code true} if long jumpable
  770.      * @since 1.3
  771.      */
  772.     public boolean isLongJumpable() {
  773.         return isAssignableTo(org.apache.commons.rng.LongJumpableUniformRandomProvider.class);
  774.     }

  775.     /**
  776.      * Checks whether the implementing class represented by this random source
  777.      * supports the {@link org.apache.commons.rng.SplittableUniformRandomProvider
  778.      * SplittableUniformRandomProvider} interface. If {@code true} the instance returned
  779.      * by {@link #create(RandomSource)} may be cast to the interface; otherwise a class
  780.      * cast exception will occur.
  781.      *
  782.      * <p>Usage example:</p>
  783.      * <pre><code>
  784.      *  RandomSource source = ...;
  785.      *  if (source.isSplittable()) {
  786.      *      SplittableUniformRandomProvider rng =
  787.      *          (SplittableUniformRandomProvider) source.create();
  788.      *  }
  789.      * </code></pre>
  790.      *
  791.      * @return {@code true} if splittable
  792.      * @since 1.5
  793.      */
  794.     public boolean isSplittable() {
  795.         return isAssignableTo(org.apache.commons.rng.SplittableUniformRandomProvider.class);
  796.     }

  797.     /**
  798.      * Determines if the implementing class represented by this random source is either the same
  799.      * as, or is a subclass or subinterface of, the class or interface represented
  800.      * by the specified {@code Class} parameter. It returns true if so; otherwise it returns
  801.      * false.
  802.      *
  803.      * @param type the {@code Class} object to be checked
  804.      * @return the boolean value indicating whether the class of this random source
  805.      * can be assigned to objects of the specified type
  806.      */
  807.     private boolean isAssignableTo(Class<?> type) {
  808.         return type.isAssignableFrom(internalIdentifier.getRng());
  809.     }

  810.     /**
  811.      * Creates a random number generator with a random seed.
  812.      *
  813.      * <p>Usage example:</p>
  814.      * <pre><code>
  815.      *  UniformRandomProvider rng = RandomSource.XO_RO_SHI_RO_128_PP.create();
  816.      * </code></pre>
  817.      * <p>or, if a {@link RestorableUniformRandomProvider "save/restore"} functionality is needed,</p>
  818.      * <pre><code>
  819.      *  RestorableUniformRandomProvider rng = RandomSource.XO_RO_SHI_RO_128_PP.create();
  820.      * </code></pre>
  821.      *
  822.      * <p>This method will raise an exception if the generator requires arguments in addition
  823.      * to a seed (e.g. {@link #TWO_CMRES_SELECT}).</p>
  824.      *
  825.      * @return the RNG.
  826.      * @throws IllegalArgumentException if the generator requires arguments in addition
  827.      * to a seed.
  828.      *
  829.      * @see #create(Object,Object[])
  830.      * @since 1.4
  831.      */
  832.     public RestorableUniformRandomProvider create() {
  833.         return ProviderBuilder.create(getInternalIdentifier());
  834.     }

  835.     /**
  836.      * Creates a random number generator with the given {@code seed}.
  837.      *
  838.      * <p>Usage example:</p>
  839.      * <pre><code>
  840.      *  UniformRandomProvider rng = RandomSource.XO_RO_SHI_RO_128_PP.create(0x123abcL);
  841.      *  UniformRandomProvider rng = RandomSource.TWO_CMRES_SELECT.create(26219, 6, 9);
  842.      *  // null seed with arguments
  843.      *  UniformRandomProvider rng = RandomSource.TWO_CMRES_SELECT.create((Object) null, 6, 9);
  844.      * </code></pre>
  845.      *
  846.      * <p>Valid types for the {@code seed} are:</p>
  847.      *  <ul>
  848.      *   <li>{@code Integer} (or {@code int})</li>
  849.      *   <li>{@code Long} (or {@code long})</li>
  850.      *   <li>{@code int[]}</li>
  851.      *   <li>{@code long[]}</li>
  852.      *   <li>{@code byte[]}</li>
  853.      *  </ul>
  854.      *
  855.      * <p>Notes:</p>
  856.      * <ul>
  857.      *  <li>
  858.      *   When the seed type passed as argument is more complex (i.e. more
  859.      *   bits can be independently chosen) than the generator's
  860.      *   {@link #isNativeSeed(Object) native type}, the conversion of a
  861.      *   set of different seeds will necessarily result in the same value
  862.      *   of the native seed type.
  863.      *  </li>
  864.      *  <li>
  865.      *   When the native seed type is an array, the same remark applies
  866.      *   when the array contains more bits than the state of the generator.
  867.      *  </li>
  868.      *  <li>
  869.      *   When the {@code seed} is {@code null}, a seed of the native type
  870.      *   will be generated. If the native type is an array, the generated
  871.      *   size is limited a maximum of 128.
  872.      *  </li>
  873.      * </ul>
  874.      *
  875.      * <p>This method will raise an exception if the additional arguments for
  876.      * the implementation's constructor are incorrect (e.g. {@link #TWO_CMRES_SELECT}).
  877.      * This includes the case where arguments are supplied and the implementation
  878.      * does not require additional arguments.</p>
  879.      *
  880.      * @param seed Seed value.  It can be {@code null} (in which case a
  881.      * random value will be used).
  882.      * @param data Additional arguments to the implementation's constructor.
  883.      * Please refer to the documentation of each specific implementation.
  884.      * @return the RNG.
  885.      * @throws IllegalArgumentException if the argument data required to initialize the
  886.      * generator is incorrect.
  887.      * @throws UnsupportedOperationException if the type of the {@code seed}
  888.      * is invalid.
  889.      *
  890.      * @see #create()
  891.      * @since 1.4
  892.      */
  893.     public RestorableUniformRandomProvider create(Object seed,
  894.                                                   Object... data) {
  895.         return ProviderBuilder.create(getInternalIdentifier(), seed, data);
  896.     }

  897.     /**
  898.      * Creates a random number generator with a random seed.
  899.      *
  900.      * <p>Usage example:</p>
  901.      * <pre><code>
  902.      *  UniformRandomProvider rng = RandomSource.create(RandomSource.MT);
  903.      * </code></pre>
  904.      * <p>or, if a {@link RestorableUniformRandomProvider "save/restore"} functionality is needed,</p>
  905.      * <pre><code>
  906.      *  RestorableUniformRandomProvider rng = RandomSource.create(RandomSource.MT);
  907.      * </code></pre>
  908.      *
  909.      * <p>This method will raise an exception if the generator requires arguments in addition
  910.      * to a seed (e.g. {@link #TWO_CMRES_SELECT}).</p>
  911.      *
  912.      * @param source RNG type.
  913.      * @return the RNG.
  914.      * @throws IllegalArgumentException if the generator requires arguments in addition
  915.      * to a seed.
  916.      *
  917.      * @see #create(RandomSource,Object,Object[])
  918.      * @deprecated It is preferred to use the {@link RandomSource#create()} instance method.
  919.      */
  920.     @Deprecated
  921.     public static RestorableUniformRandomProvider create(RandomSource source) {
  922.         return ProviderBuilder.create(source.getInternalIdentifier());
  923.     }

  924.     /**
  925.      * Creates a random number generator with the given {@code seed}.
  926.      *
  927.      * <p>Usage example:</p>
  928.      * <pre><code>
  929.      *  UniformRandomProvider rng = RandomSource.create(RandomSource.XO_RO_SHI_RO_128_PP, 0x123abcL);
  930.      *  UniformRandomProvider rng = RandomSource.create(RandomSource.TWO_CMRES_SELECT, 26219, 6, 9);
  931.      * </code></pre>
  932.      *
  933.      * <p>Valid types for the {@code seed} are:</p>
  934.      *  <ul>
  935.      *   <li>{@code Integer} (or {@code int})</li>
  936.      *   <li>{@code Long} (or {@code long})</li>
  937.      *   <li>{@code int[]}</li>
  938.      *   <li>{@code long[]}</li>
  939.      *   <li>{@code byte[]}</li>
  940.      *  </ul>
  941.      *
  942.      * <p>Notes:</p>
  943.      * <ul>
  944.      *  <li>
  945.      *   When the seed type passed as argument is more complex (i.e. more
  946.      *   bits can be independently chosen) than the generator's
  947.      *   {@link #isNativeSeed(Object) native type}, the conversion of a
  948.      *   set of different seeds will necessarily result in the same value
  949.      *   of the native seed type.
  950.      *  </li>
  951.      *  <li>
  952.      *   When the native seed type is an array, the same remark applies
  953.      *   when the array contains more bits than the state of the generator.
  954.      *  </li>
  955.      *  <li>
  956.      *   When the {@code seed} is {@code null}, a seed of the native type
  957.      *   will be generated. If the native type is an array, the generated
  958.      *   size is limited a maximum of 128.
  959.      *  </li>
  960.      * </ul>
  961.      *
  962.      * <p>This method will raise an exception if the additional arguments for
  963.      * the implementation's constructor are incorrect (e.g. {@link #TWO_CMRES_SELECT}).
  964.      * This includes the case where arguments are supplied and the implementation
  965.      * does not require additional arguments.</p>
  966.      *
  967.      * @param source RNG type.
  968.      * @param seed Seed value.  It can be {@code null} (in which case a
  969.      * random value will be used).
  970.      * @param data Additional arguments to the implementation's constructor.
  971.      * Please refer to the documentation of each specific implementation.
  972.      * @return the RNG.
  973.      * @throws IllegalArgumentException if the argument data required to initialize the
  974.      * generator is incorrect.
  975.      * @throws UnsupportedOperationException if the type of the {@code seed}
  976.      * is invalid.
  977.      *
  978.      * @see #create(RandomSource)
  979.      * @deprecated It is preferred to use the {@link RandomSource#create(Object, Object...)} instance method.
  980.      */
  981.     @Deprecated
  982.     public static RestorableUniformRandomProvider create(RandomSource source,
  983.                                                          Object seed,
  984.                                                          Object... data) {
  985.         return ProviderBuilder.create(source.getInternalIdentifier(), seed, data);
  986.     }

  987.     /**
  988.      * Creates a number for use as a seed.
  989.      *
  990.      * @return a random number.
  991.      */
  992.     public static int createInt() {
  993.         return SeedFactory.createInt();
  994.     }

  995.     /**
  996.      * Creates a number for use as a seed.
  997.      *
  998.      * @return a random number.
  999.      */
  1000.     public static long createLong() {
  1001.         return SeedFactory.createLong();
  1002.     }

  1003.     /**
  1004.      * Creates an array of numbers for use as a seed.
  1005.      *
  1006.      * @param n Size of the array to create.
  1007.      * @return an array of {@code n} random numbers.
  1008.      */
  1009.     public static int[] createIntArray(int n) {
  1010.         return SeedFactory.createIntArray(n);
  1011.     }

  1012.     /**
  1013.      * Creates an array of numbers for use as a seed.
  1014.      *
  1015.      * @param n Size of the array to create.
  1016.      * @return an array of {@code n} random numbers.
  1017.      */
  1018.     public static long[] createLongArray(int n) {
  1019.         return SeedFactory.createLongArray(n);
  1020.     }

  1021.     /**
  1022.      * Wraps the given {@code delegate} generator in a new instance that
  1023.      * only provides access to the {@link UniformRandomProvider} methods.
  1024.      *
  1025.      * <p>This method can be used to prevent access to any methods of the {@code delegate}
  1026.      * that are not defined in the {@link UniformRandomProvider} interface.
  1027.      * For example this will prevent access to the "save/restore" functionality of
  1028.      * any {@link RestorableUniformRandomProvider} {@link #create() created}
  1029.      * by the {@link RandomSource} factory methods, or will prevent access to the jump
  1030.      * functionality of generators.
  1031.      *
  1032.      * <p>Since the method applies to more than the {@link RestorableUniformRandomProvider}
  1033.      * interface it is left to the caller to determine if any methods require hiding,
  1034.      * for example:
  1035.      *
  1036.      * <pre><code>
  1037.      * UniformRandomProvider rng = ...;
  1038.      * if (rng instanceof JumpableUniformRandomProvider) {
  1039.      *    rng = RandomSource.unrestorable(rng);
  1040.      * }
  1041.      * </code></pre>
  1042.      *
  1043.      * @param delegate Generator to which calls will be delegated.
  1044.      * @return a new instance
  1045.      */
  1046.     public static UniformRandomProvider unrestorable(final UniformRandomProvider delegate) {
  1047.         return new UniformRandomProvider() {
  1048.             @Override
  1049.             public void nextBytes(byte[] bytes) {
  1050.                 delegate.nextBytes(bytes);
  1051.             }

  1052.             @Override
  1053.             public void nextBytes(byte[] bytes,
  1054.                                   int start,
  1055.                                   int len) {
  1056.                 delegate.nextBytes(bytes, start, len);
  1057.             }

  1058.             @Override
  1059.             public int nextInt() {
  1060.                 return delegate.nextInt();
  1061.             }

  1062.             @Override
  1063.             public int nextInt(int n) {
  1064.                 return delegate.nextInt(n);
  1065.             }

  1066.             @Override
  1067.             public int nextInt(int origin, int bound) {
  1068.                 return delegate.nextInt(origin, bound);
  1069.             }

  1070.             @Override
  1071.             public long nextLong() {
  1072.                 return delegate.nextLong();
  1073.             }

  1074.             @Override
  1075.             public long nextLong(long n) {
  1076.                 return delegate.nextLong(n);
  1077.             }

  1078.             @Override
  1079.             public long nextLong(long origin, long bound) {
  1080.                 return delegate.nextLong(origin, bound);
  1081.             }

  1082.             @Override
  1083.             public boolean nextBoolean() {
  1084.                 return delegate.nextBoolean();
  1085.             }

  1086.             @Override
  1087.             public float nextFloat() {
  1088.                 return delegate.nextFloat();
  1089.             }

  1090.             @Override
  1091.             public float nextFloat(float bound) {
  1092.                 return delegate.nextFloat(bound);
  1093.             }

  1094.             @Override
  1095.             public float nextFloat(float origin, float bound) {
  1096.                 return delegate.nextFloat(origin, bound);
  1097.             }

  1098.             @Override
  1099.             public double nextDouble() {
  1100.                 return delegate.nextDouble();
  1101.             }

  1102.             @Override
  1103.             public double nextDouble(double bound) {
  1104.                 return delegate.nextDouble(bound);
  1105.             }

  1106.             @Override
  1107.             public double nextDouble(double origin, double bound) {
  1108.                 return delegate.nextDouble(origin, bound);
  1109.             }

  1110.             @Override
  1111.             public IntStream ints() {
  1112.                 return delegate.ints();
  1113.             }

  1114.             @Override
  1115.             public IntStream ints(int origin, int bound) {
  1116.                 return delegate.ints(origin, bound);
  1117.             }

  1118.             @Override
  1119.             public IntStream ints(long streamSize) {
  1120.                 return delegate.ints(streamSize);
  1121.             }

  1122.             @Override
  1123.             public IntStream ints(long streamSize, int origin, int bound) {
  1124.                 return delegate.ints(streamSize, origin, bound);
  1125.             }

  1126.             @Override
  1127.             public LongStream longs() {
  1128.                 return delegate.longs();
  1129.             }

  1130.             @Override
  1131.             public LongStream longs(long origin, long bound) {
  1132.                 return delegate.longs(origin, bound);
  1133.             }

  1134.             @Override
  1135.             public LongStream longs(long streamSize) {
  1136.                 return delegate.longs(streamSize);
  1137.             }

  1138.             @Override
  1139.             public LongStream longs(long streamSize, long origin, long bound) {
  1140.                 return delegate.longs(streamSize, origin, bound);
  1141.             }

  1142.             @Override
  1143.             public DoubleStream doubles() {
  1144.                 return delegate.doubles();
  1145.             }

  1146.             @Override
  1147.             public DoubleStream doubles(double origin, double bound) {
  1148.                 return delegate.doubles(origin, bound);
  1149.             }

  1150.             @Override
  1151.             public DoubleStream doubles(long streamSize) {
  1152.                 return delegate.doubles(streamSize);
  1153.             }

  1154.             @Override
  1155.             public DoubleStream doubles(long streamSize, double origin, double bound) {
  1156.                 return delegate.doubles(streamSize, origin, bound);
  1157.             }

  1158.             @Override
  1159.             public String toString() {
  1160.                 return delegate.toString();
  1161.             }
  1162.         };
  1163.     }
  1164. }