RandomGeneratorFactory also provides
methods for selecting random number generator algorithms.
A specific RandomGeneratorFactory can be located by using the
RandomGeneratorFactory#of(String) method, where the argument string
is the name of the algorithm
required. The method
RandomGeneratorFactory#all() produces a non-empty Stream of all available
RandomGeneratorFactorys that can be searched
to locate a RandomGeneratorFactory suitable to the task.
There are three methods for constructing a RandomGenerator instance,
depending on the type of initial seed required.
RandomGeneratorFactory#create(long) is used for long
seed construction,
RandomGeneratorFactory#create(byte[]) is used for byte[]
seed construction, and
RandomGeneratorFactory#create() is used for random seed
construction. Example;
RandomGeneratorFactory<RandomGenerator> factory = RandomGeneratorFactory.of("Random");
for (int i = 0; i < 10; i++) {
new Thread(() -> {
RandomGenerator random = factory.create(100L);
System.out.println(random.nextDouble());
}).start();
}
RandomGeneratorFactory#all(). In this example, the code
locates the RandomGeneratorFactory that produces
RandomGenerators
with the highest number of state bits.
RandomGeneratorFactory<RandomGenerator> best = RandomGeneratorFactory.all()
.filter(rgf -> !rgf.name().equals("SecureRandom")) // SecureRandom has MAX_VALUE stateBits.
.sorted(Comparator.comparingInt(RandomGeneratorFactory<RandomGenerator>::stateBits).reversed())
.findFirst()
.orElse(RandomGeneratorFactory.of("Random"));
System.out.println(best.name() + " in " + best.group() + " was selected");
RandomGenerator rng = best.create();
System.out.println(rng.nextLong());
java.util.random
| Modifier and Type | Class and Description |
|---|---|
| private static record |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private final RandomGeneratorFactory. | properties
Random generator properties. |
| Access | Constructor and Description |
|---|---|
| private | RandomGeneratorFactory(RandomGeneratorFactory.
Random generator properties. propertiesPrivate constructor. |
| Modifier and Type | Method and Description |
|---|---|
| public static Stream | Returns: a non-empty stream of all availableRandomGeneratorFactory(s).Returns a non-empty stream of available |
| public T | Returns: new instance ofRandomGenerator.Create an instance of |
| public T | Returns: new instance ofRandomGenerator.long random seed value. seed)Create an instance of |
| public T | Returns: new instance ofRandomGenerator.byte array random seed value. seed)Create an instance of |
| public int | Returns: the equidistribution of the algorithm.Returns the equidistribution of the algorithm. |
| pack-priv static < Sub-interface of T extends RandomGenerator> RandomGeneratorFactoryRandomGenerator to produce | Returns: Factory ofRandomGeneratorName of random number algorithm to use name, Class<T> Sub-interface of category)RandomGenerator to type checkReturns a |
| private static RandomGeneratorFactory. | Returns: A RandomGeneratorProperties instance matching name and category.Name of RandomGenerator name, Class<? extends RandomGenerator> Interface category, sub-interface of category)RandomGenerator.Returns a RandomGeneratorProperties instance matching name and category. |
| public static RandomGeneratorFactory | Returns: aRandomGeneratorFactoryReturns a |
| private static Map | Returns: Map of random generator classes.Returns the factory map, lazily constructing the map on first call. |
| public String | |
| public boolean | Returns: true if random generator is arbitrarily jumpable.Return true if random generator can jump an arbitrarily specified distant point in the state cycle. |
| public boolean | Returns: true if the implementation of RandomGenerator (algorithm) has been marked for deprecationReturn true if the implementation of RandomGenerator (algorithm) has been marked for deprecation. |
| public boolean | Returns: true if random generator is generated by hardware.Return true if random generator uses a hardware device (HRNG) to produce entropic input. |
| public boolean | Returns: true if random generator is jumpable.Return true if random generator can jump a specified distant point in the state cycle. |
| public boolean | Returns: true if random generator is leapable.Return true if random generator is jumpable and can leap to a very distant point in the state cycle. |
| public boolean | Returns: true if random generator is splittable.Return true if random generator can be cloned into a separate object with the same properties but positioned further in the state cycle. |
| public boolean | Returns: true if random generator is statistical.Return true if random generator is computed using an arithmetic algorithm and is statistically deterministic. |
| public boolean | Returns: true if random generator is stochastic.Return true if random generator is computed using external or entropic sources as inputs. |
| public boolean | Returns: true if random generator is streamable.Return true if random generator can be used to create
|
| private boolean | Returns: true if the random generator class is a subclass of the category.Interface category, sub-interface of category)RandomGenerator.Return true if the random generator class is a subclass of the category. |
| private static boolean | Returns: true if rgClass is a subclass of the category.Interface category, sub-interface of category, Class<? extends RandomGenerator> RandomGenerator.Class that is being filtered. rgClass)Return true if rgClass is a subclass of the category. |
| public String | |
| pack-priv static < Sub-interface of T extends RandomGenerator> TRandomGenerator to produce | Returns: An instance ofRandomGeneratorName of random number algorithm to use name, Class<T> Sub-interface of category)RandomGenerator to type checkReturns a |
| public static < Sub-interface of T extends RandomGenerator> RandomGeneratorFactoryRandomGenerator to produce | of(String
Name of random number generator
algorithm name)Returns a |
| public BigInteger | |
| public int |
| DEFAULT_ALGORITHM | back to summary |
|---|---|
| private static final String DEFAULT_ALGORITHM | |
| properties | back to summary |
|---|---|
| private final RandomGeneratorFactory. Random generator properties. | |
| RandomGeneratorFactory | back to summary |
|---|---|
| private RandomGeneratorFactory(RandomGeneratorFactory. Private constructor.
| |
| all | back to summary |
|---|---|
| public static Stream Returns a non-empty stream of available
| |
| create | back to summary |
|---|---|
| public T create() Create an instance of
| |
| create | back to summary |
|---|---|
| public T create(long seed) Create an instance of
| |
| create | back to summary |
|---|---|
| public T create(byte[] seed) Create an instance of
| |
| equidistribution | back to summary |
|---|---|
| public int equidistribution() Returns the equidistribution of the algorithm.
| |
| factoryOf | back to summary |
|---|---|
| pack-priv static <T extends RandomGenerator> RandomGeneratorFactory Returns a
| |
| findClass | back to summary |
|---|---|
| private static RandomGeneratorFactory. Returns a RandomGeneratorProperties instance matching name and category.
| |
| getDefault | back to summary |
|---|---|
| public static RandomGeneratorFactory Returns a Implementation Specification Since algorithms will improve over time, there is no guarantee that this method will return the same algorithm over time. | |
| getFactoryMap | back to summary |
|---|---|
| private static Map Returns the factory map, lazily constructing the map on first call.
| |
| group | back to summary |
|---|---|
| public String group() Return the group name of the algorithm used by the random number generator. | |
| isArbitrarilyJumpable | back to summary |
|---|---|
| public boolean isArbitrarilyJumpable() Return true if random generator can jump an arbitrarily specified distant point in the state cycle.
| |
| isDeprecated | back to summary |
|---|---|
| public boolean isDeprecated() Return true if the implementation of RandomGenerator (algorithm) has been marked for deprecation. Implementation Note Random number generator algorithms evolve over time; new algorithms will be introduced and old algorithms will lose standing. If an older algorithm is deemed unsuitable for continued use, it will be marked as deprecated to indicate that it may be removed at some point in the future.
| |
| isHardware | back to summary |
|---|---|
| public boolean isHardware() Return true if random generator uses a hardware device (HRNG) to produce entropic input.
| |
| isJumpable | back to summary |
|---|---|
| public boolean isJumpable() Return true if random generator can jump a specified distant point in the state cycle.
| |
| isLeapable | back to summary |
|---|---|
| public boolean isLeapable() Return true if random generator is jumpable and can leap to a very distant point in the state cycle.
| |
| isSplittable | back to summary |
|---|---|
| public boolean isSplittable() Return true if random generator can be cloned into a separate object with the same properties but positioned further in the state cycle.
| |
| isStatistical | back to summary |
|---|---|
| public boolean isStatistical() Return true if random generator is computed using an arithmetic algorithm and is statistically deterministic.
| |
| isStochastic | back to summary |
|---|---|
| public boolean isStochastic() Return true if random generator is computed using external or entropic sources as inputs.
| |
| isStreamable | back to summary |
|---|---|
| public boolean isStreamable() Return true if random generator can be used to create
| |
| isSubclass | back to summary |
|---|---|
| private boolean isSubclass(Class<? extends RandomGenerator> category) Return true if the random generator class is a subclass of the category.
| |
| isSubclass | back to summary |
|---|---|
| private static boolean isSubclass(Class<? extends RandomGenerator> category, Class<? extends RandomGenerator> rgClass) Return true if rgClass is a subclass of the category.
| |
| name | back to summary |
|---|---|
| public String name() Return the name of the algorithm used by the random number generator. | |
| of | back to summary |
|---|---|
| pack-priv static <T extends RandomGenerator> T of(String name, Class<T> category) throws IllegalArgumentException Returns a
| |
| of | back to summary |
|---|---|
| public static <T extends RandomGenerator> RandomGeneratorFactory Returns a
| |
| period | back to summary |
|---|---|
| public BigInteger period() Return the period of the algorithm used by the random number generator. Returns BigInteger.ZERO if period is not determinable.
| |
| stateBits | back to summary |
|---|---|
| public int stateBits() Returns number of bits used by the algorithm to maintain state of seed.
| |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private static final int | |
| private static final int | |
| private final int | equidistribution
Record Component accessed by equidistribution(). |
| private static final Map | |
| private final int | |
| private final String | |
| private static final int | |
| private final int | |
| private static final int | |
| private final int | |
| private final int | |
| private static final int | |
| private final String | |
| private final Class | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| private | RandomGeneratorProperties(Class<? extends RandomGenerator> rgClass, String name, String group, int i, int j, int k, int equidistribution, int flags)
|
| Modifier and Type | Method and Description |
|---|---|
| private RandomGenerator | |
| private RandomGenerator | |
| private RandomGenerator | |
| private static Map | Returns: Map of RandomGeneratorProperties.Returns the factory map, lazily constructing it on first use. |
| private static int | |
| private static Map. | entry(Class<? extends RandomGenerator> rgClass, String name, String group, int i, int j, int k, int equidistribution, int flags)
|
| public final boolean | equals(Object o)
Implements abstract java. Indicates whether some other object is "equal to" this one. |
| public int | |
| public int | |
| public String | |
| public final int | |
| public int | |
| private boolean | |
| private boolean | |
| private boolean | |
| private boolean | |
| public int | |
| public int | |
| public String | |
| private BigInteger | |
| public Class | |
| private int | |
| public final String | toString()
Implements abstract java. Returns a string representation of the record. |
| ALL_CONSTRUCTORS | back to summary |
|---|---|
| private static final int ALL_CONSTRUCTORS | |
| BYTE_ARRAY_SEED | back to summary |
|---|---|
| private static final int BYTE_ARRAY_SEED | |
| DEPRECATED | back to summary |
|---|---|
| private static final int DEPRECATED | |
| equidistribution | back to summary |
|---|---|
| private final int equidistribution Record Component accessed by equidistribution(). | |
| FACTORY_MAP | back to summary |
|---|---|
| private static final Map<String, RandomGeneratorFactory. | |
| flags | back to summary |
|---|---|
| private final int flags Record Component accessed by flags(). | |
| group | back to summary |
|---|---|
| private final String group Record Component accessed by group(). | |
| HARDWARE | back to summary |
|---|---|
| private static final int HARDWARE | |
| i | back to summary |
|---|---|
| private final int i Record Component accessed by i(). | |
| INSTANTIABLE | back to summary |
|---|---|
| private static final int INSTANTIABLE | |
| j | back to summary |
|---|---|
| private final int j Record Component accessed by j(). | |
| k | back to summary |
|---|---|
| private final int k Record Component accessed by k(). | |
| LONG_SEED | back to summary |
|---|---|
| private static final int LONG_SEED | |
| name | back to summary |
|---|---|
| private final String name Record Component accessed by name(). | |
| rgClass | back to summary |
|---|---|
| private final Class<? extends RandomGenerator> rgClass Record Component accessed by rgClass(). | |
| STOCHASTIC | back to summary |
|---|---|
| private static final int STOCHASTIC | |
| RandomGeneratorProperties | back to summary |
|---|---|
| private RandomGeneratorProperties(Class<? extends RandomGenerator> rgClass, String name, String group, int i, int j, int k, int equidistribution, int flags) | |
| create | back to summary |
|---|---|
| private RandomGenerator create() | |
| create | back to summary |
|---|---|
| private RandomGenerator create(long seed) | |
| create | back to summary |
|---|---|
| private RandomGenerator create(byte[] seed) | |
| createFactoryMap | back to summary |
|---|---|
| private static Map Returns the factory map, lazily constructing it on first use. Although Currently, no algorithm is deprecated.
| |
| deprecationBit | back to summary |
|---|---|
| private static int deprecationBit(Class<? extends RandomGenerator> rgClass) | |
| entry | back to summary |
|---|---|
| private static Map. | |
| equals | back to summary |
|---|---|
| public final boolean equals(Object o) Implements abstract java. Doc from java. Indicates whether some other object is "equal to" this one. In addition
to the general contract of
R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
| |
| equidistribution | back to summary |
|---|---|
| public int equidistribution() Record Component getter of equidistribution. | |
| flags | back to summary |
|---|---|
| public int flags() Record Component getter of flags. | |
| group | back to summary |
|---|---|
| public String group() Record Component getter of group. | |
| hashCode | back to summary |
|---|---|
| public final int hashCode() Implements abstract java. Doc from java. Returns a hash code value for the record.
Obeys the general contract of | |
| i | back to summary |
|---|---|
| public int i() Record Component getter of i. | |
| isDeprecated | back to summary |
|---|---|
| private boolean isDeprecated() | |
| isHardware | back to summary |
|---|---|
| private boolean isHardware() | |
| isInstantiable | back to summary |
|---|---|
| private boolean isInstantiable() | |
| isStochastic | back to summary |
|---|---|
| private boolean isStochastic() | |
| j | back to summary |
|---|---|
| public int j() Record Component getter of j. | |
| k | back to summary |
|---|---|
| public int k() Record Component getter of k. | |
| name | back to summary |
|---|---|
| public String name() Record Component getter of name. | |
| period | back to summary |
|---|---|
| private BigInteger period() | |
| rgClass | back to summary |
|---|---|
| public Class Record Component getter of rgClass. | |
| stateBits | back to summary |
|---|---|
| private int stateBits() | |
| toString | back to summary |
|---|---|
| public final String toString() Implements abstract java. Doc from java. Returns a string representation of the record.
In accordance with the general contract of In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves. | |