--- a/src/java.base/share/classes/java/util/random/RandomGenerator.java Fri Jul 26 15:37:05 2019 -0300
+++ b/src/java.base/share/classes/java/util/random/RandomGenerator.java Wed Aug 07 15:35:55 2019 -0300
@@ -26,11 +26,11 @@
package java.util.random;
import java.math.BigInteger;
+import java.util.Objects;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
-import java.util.stream.StreamSupport;
/**
* The {@link RandomGenerator} interface is designed to provide a common protocol for objects
@@ -90,6 +90,122 @@
public interface RandomGenerator {
/**
+ * Supported randpm number Algorithms.
+ */
+ public enum Algorithm {
+ /**
+ * L32X64MixRandom algorithm
+ */
+ L32X64MixRandom("L32X64MixRandom"),
+ /**
+ * L64X1024MixRandom algorithm
+ */
+ L64X1024MixRandom("L64X1024MixRandom"),
+ /**
+ * L64X1024Random algorithm
+ */
+ L64X1024Random("L64X1024Random"),
+ /**
+ * L64X128MixRandom algorithm
+ */
+ L64X128MixRandom("L64X128MixRandom"),
+ /**
+ * L64X128Random algorithm
+ */
+ L64X128Random("L64X128Random"),
+ /**
+ * L64X256MixRandom algorithm
+ */
+ L64X256MixRandom("L64X256MixRandom"),
+ /**
+ * L64X256Random algorithm
+ */
+ L64X256Random("L64X256Random"),
+ /**
+ * L128X256MixRandom algorithm
+ */
+ L128X256MixRandom("L128X256MixRandom"),
+ /**
+ * MRG32k3a algorithm
+ */
+ MRG32k3a("MRG32k3a"),
+ /**
+ * Xoroshiro128Plus algorithm
+ */
+ Xoroshiro128Plus("Xoroshiro128Plus"),
+ /**
+ * Xoroshiro128StarStar algorithm
+ */
+ Xoroshiro128StarStar("Xoroshiro128StarStar"),
+ /**
+ * Xoshiro256StarStar algorithm
+ */
+ Xoshiro256StarStar("Xoshiro256StarStar");
+
+ private String name;
+
+ Algorithm(String name) {
+ this.name = name;
+ }
+
+ public String toString() {
+ return name;
+ }
+ }
+
+ /**
+ * Returns an instance of {@link RandomGenerator} that utilizes the
+ * {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return An instance of {@link RandomGenerator}
+ */
+ public static RandomGenerator of(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.of(name, RandomGenerator.class);
+ }
+
+ /**
+ * Returns an instance of {@link RandomGenerator} that utilizes the
+ * specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return An instance of {@link RandomGenerator}
+ */
+ public static RandomGenerator of(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.of(algorithm.toString(), RandomGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link RandomGenerator} that utilizes the {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return Factory of {@link RandomGenerator}
+ */
+ public static RandomGeneratorFactory<RandomGenerator> factoryOf(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.factoryOf(name, RandomGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link RandomGenerator} that utilizes the specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return Factory of {@link RandomGenerator}
+ */
+ public static RandomGeneratorFactory<RandomGenerator> factoryOf(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.factoryOf(algorithm.toString(), RandomGenerator.class);
+ }
+
+ /**
* Returns an effectively unlimited stream of pseudorandomly chosen
* {@code double} values.
*
@@ -672,6 +788,59 @@
* @since 14
*/
public interface StreamableGenerator extends RandomGenerator {
+
+ /**
+ * Returns an instance of {@link StreamableGenerator} that utilizes the
+ * {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return An instance of {@link StreamableGenerator}
+ */
+ public static StreamableGenerator of(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.of(name, StreamableGenerator.class);
+ }
+
+ /**
+ * Returns an instance of {@link StreamableGenerator} that utilizes the
+ * specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return An instance of {@link StreamableGenerator}
+ */
+ public static StreamableGenerator of(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.of(algorithm.toString(), StreamableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link StreamableGenerator} that utilizes the {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return Factory of {@link StreamableGenerator}
+ */
+ public static RandomGeneratorFactory<StreamableGenerator> factoryOf(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.factoryOf(name, StreamableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link StreamableGenerator} that utilizes the specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return Factory of {@link StreamableGenerator}
+ */
+ public static RandomGeneratorFactory<StreamableGenerator> factoryOf(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.factoryOf(algorithm.toString(), StreamableGenerator.class);
+ }
+
/**
* Returns an effectively unlimited stream of objects, each of
* which implements the {@link RandomGenerator} interface. Ideally the
@@ -748,6 +917,58 @@
public interface SplittableGenerator extends StreamableGenerator {
/**
+ * Returns an instance of {@link SplittableGenerator} that utilizes the
+ * {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return An instance of {@link SplittableGenerator}
+ */
+ public static SplittableGenerator of(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.of(name, SplittableGenerator.class);
+ }
+
+ /**
+ * Returns an instance of {@link SplittableGenerator} that utilizes the
+ * specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return An instance of {@link SplittableGenerator}
+ */
+ public static SplittableGenerator of(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.of(algorithm.toString(), SplittableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link SplittableGenerator} that utilizes the {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return Factory of {@link SplittableGenerator}
+ */
+ public static RandomGeneratorFactory<SplittableGenerator> factoryOf(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.factoryOf(name, SplittableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link SplittableGenerator} that utilizes the specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return Factory of {@link SplittableGenerator}
+ */
+ public static RandomGeneratorFactory<SplittableGenerator> factoryOf(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.factoryOf(algorithm.toString(), SplittableGenerator.class);
+ }
+
+ /**
* Returns a new pseudorandom number generator, split off from
* this one, that implements the {@link RandomGenerator} and {@link SplittableGenerator}
* interfaces.
@@ -910,6 +1131,59 @@
* @since 14
*/
public interface JumpableGenerator extends StreamableGenerator {
+
+ /**
+ * Returns an instance of {@link JumpableGenerator} that utilizes the
+ * {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return An instance of {@link JumpableGenerator}
+ */
+ public static JumpableGenerator of(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.of(name, JumpableGenerator.class);
+ }
+
+ /**
+ * Returns an instance of {@link JumpableGenerator} that utilizes the
+ * specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return An instance of {@link JumpableGenerator}
+ */
+ public static JumpableGenerator of(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.of(algorithm.toString(), JumpableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link JumpableGenerator} that utilizes the {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return Factory of {@link JumpableGenerator}
+ */
+ public static RandomGeneratorFactory<JumpableGenerator> factoryOf(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.factoryOf(name, JumpableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link JumpableGenerator} that utilizes the specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return Factory of {@link JumpableGenerator}
+ */
+ public static RandomGeneratorFactory<JumpableGenerator> factoryOf(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.factoryOf(algorithm.toString(), JumpableGenerator.class);
+ }
+
/**
* Returns a new generator whose internal state is an exact copy of this generator (therefore
* their future behavior should be identical if subjected to the same series of operations).
@@ -1046,6 +1320,59 @@
* @since 14
*/
public interface LeapableGenerator extends JumpableGenerator {
+
+ /**
+ * Returns an instance of {@link LeapableGenerator} that utilizes the
+ * {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return An instance of {@link LeapableGenerator}
+ */
+ public static LeapableGenerator of(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.of(name, LeapableGenerator.class);
+ }
+
+ /**
+ * Returns an instance of {@link LeapableGenerator} that utilizes the
+ * specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return An instance of {@link LeapableGenerator}
+ */
+ public static LeapableGenerator of(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.of(algorithm.toString(), LeapableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link LeapableGenerator} that utilizes the {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return Factory of {@link LeapableGenerator}
+ */
+ public static RandomGeneratorFactory<LeapableGenerator> factoryOf(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.factoryOf(name, LeapableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link LeapableGenerator} that utilizes the specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return Factory of {@link LeapableGenerator}
+ */
+ public static RandomGeneratorFactory<LeapableGenerator> factoryOf(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.factoryOf(algorithm.toString(), LeapableGenerator.class);
+ }
+
/**
* Returns a new generator whose internal state is an exact copy of this generator (therefore
* their future behavior should be identical if subjected to the same series of operations).
@@ -1155,6 +1482,59 @@
* @since 14
*/
public interface ArbitrarilyJumpableGenerator extends LeapableGenerator {
+
+ /**
+ * Returns an instance of {@link ArbitrarilyJumpableGenerator} that utilizes the
+ * {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return An instance of {@link ArbitrarilyJumpableGenerator}
+ */
+ public static ArbitrarilyJumpableGenerator of(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.of(name, ArbitrarilyJumpableGenerator.class);
+ }
+
+ /**
+ * Returns an instance of {@link ArbitrarilyJumpableGenerator} that utilizes the
+ * specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return An instance of {@link ArbitrarilyJumpableGenerator}
+ */
+ public static ArbitrarilyJumpableGenerator of(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.of(algorithm.toString(), ArbitrarilyJumpableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link ArbitrarilyJumpableGenerator} that utilizes the {@code name} algorithm.
+ *
+ * @param name Name of random number generator algorithm
+ *
+ * @return Factory of {@link ArbitrarilyJumpableGenerator}
+ */
+ public static RandomGeneratorFactory<ArbitrarilyJumpableGenerator> factoryOf(String name) {
+ Objects.requireNonNull(name);
+ return RandomGeneratorFactory.factoryOf(name, ArbitrarilyJumpableGenerator.class);
+ }
+
+ /**
+ * Returns a {@link RandomGeneratorFactory} that can produce instances
+ * of {@link ArbitrarilyJumpableGenerator} that utilizes the specified {@code algorithm}.
+ *
+ * @param algorithm Random number generator algorithm
+ *
+ * @return Factory of {@link ArbitrarilyJumpableGenerator}
+ */
+ public static RandomGeneratorFactory<ArbitrarilyJumpableGenerator> factoryOf(Algorithm algorithm) {
+ Objects.requireNonNull(algorithm);
+ return RandomGeneratorFactory.factoryOf(algorithm.toString(), ArbitrarilyJumpableGenerator.class);
+ }
+
/**
* Returns a new generator whose internal state is an exact copy of this generator (therefore
* their future behavior should be identical if subjected to the same series of operations).