Class RandomGeneratorFactory<T extends RandomGenerator>
java.lang.Object
java.util.random.RandomGeneratorFactory<T>
- Type Parameters:
- T- type of created random generator
This is a factory class for generating multiple random number generators
 of a specific algorithm.
 
 RandomGeneratorFactory also provides methods describing the attributes (or properties)
 of a generator and can be used to select random number generator
 algorithms.
 These methods are typically used in
 conjunction with 
RandomGeneratorFactory also provides
 methods for selecting random number generator algorithms.
 A specific RandomGeneratorFactory can be located by using the
 of(String) method, where the argument string
 is the name of the algorithm
 required. The method
 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.
 create(long) is used for long
 seed construction,
 create(byte[]) is used for byte[]
 seed construction, and
 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();
    }
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());
- Since:
- 17
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionstatic Stream<RandomGeneratorFactory<RandomGenerator>> all()Returns a non-empty stream of availableRandomGeneratorFactory(s).create()Create an instance ofRandomGeneratorbased on the algorithm chosen.create(byte[] seed) create(long seed) intReturns the equidistribution of the algorithm.Returns aRandomGeneratorFactorymeeting the minimal requirement of having an algorithm whose state bits are greater than or equal 64.group()Return the group name of the algorithm used by the random number generator.booleanReturn true if random generator can jump an arbitrarily specified distant point in the state cycle.booleanReturn true if the implementation of RandomGenerator (algorithm) has been marked for deprecation.booleanReturn true if random generator uses a hardware device (HRNG) to produce entropic input.booleanReturn true if random generator can jump a specified distant point in the state cycle.booleanReturn true if random generator is jumpable and can leap to a very distant point in the state cycle.booleanReturn true if random generator can be cloned into a separate object with the same properties but positioned further in the state cycle.booleanReturn true if random generator is computed using an arithmetic algorithm and is statistically deterministic.booleanReturn true if random generator is computed using external or entropic sources as inputs.booleanReturn true if random generator can be used to createStreamsof random numbers.name()Return the name of the algorithm used by the random number generator.static <T extends RandomGenerator>
 RandomGeneratorFactory<T> Returns aRandomGeneratorFactorythat can produce instances ofRandomGeneratorthat utilize thenamealgorithm.period()Return the period of the algorithm used by the random number generator.intReturns number of bits used by the algorithm to maintain state of seed.
- 
Method Details- 
ofReturns aRandomGeneratorFactorythat can produce instances ofRandomGeneratorthat utilize thenamealgorithm.- Type Parameters:
- T- Sub-interface of- RandomGeneratorto produce
- Parameters:
- name- Name of random number generator algorithm
- Returns:
- RandomGeneratorFactoryof- RandomGenerator
- Throws:
- NullPointerException- if name is null
- IllegalArgumentException- if the named algorithm is not found
 
- 
getDefaultReturns aRandomGeneratorFactorymeeting the minimal requirement of having an algorithm whose state bits are greater than or equal 64.- Implementation Requirements:
- Since algorithms will improve over time, there is no guarantee that this method will return the same algorithm over time.
- Returns:
- a RandomGeneratorFactory
 
- 
allReturns a non-empty stream of availableRandomGeneratorFactory(s). RandomGenerators that are marked as deprecated are not included in the result.- Returns:
- a non-empty stream of all available RandomGeneratorFactory(s).
 
- 
name
- 
group
- 
stateBits
- 
equidistribution
- 
periodReturn the period of the algorithm used by the random number generator. Returns BigInteger.ZERO if period is not determinable.- Returns:
- BigInteger period.
 
- 
isStatisticalpublic boolean isStatistical()Return true if random generator is computed using an arithmetic algorithm and is statistically deterministic.- Returns:
- true if random generator is statistical.
 
- 
isStochasticpublic boolean isStochastic()Return true if random generator is computed using external or entropic sources as inputs.- Returns:
- true if random generator is stochastic.
 
- 
isHardwarepublic boolean isHardware()Return true if random generator uses a hardware device (HRNG) to produce entropic input.- Returns:
- true if random generator is generated by hardware.
 
- 
isArbitrarilyJumpablepublic boolean isArbitrarilyJumpable()Return true if random generator can jump an arbitrarily specified distant point in the state cycle.- Returns:
- true if random generator is arbitrarily jumpable.
 
- 
isJumpablepublic boolean isJumpable()Return true if random generator can jump a specified distant point in the state cycle.- Returns:
- true if random generator is jumpable.
 
- 
isLeapablepublic boolean isLeapable()Return true if random generator is jumpable and can leap to a very distant point in the state cycle.- Returns:
- true if random generator is leapable.
 
- 
isSplittablepublic 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.- Returns:
- true if random generator is splittable.
 
- 
isStreamablepublic boolean isStreamable()Return true if random generator can be used to createStreamsof random numbers.- Returns:
- true if random generator is streamable.
 
- 
isDeprecatedpublic 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.
- Returns:
- true if the implementation of RandomGenerator (algorithm) has been marked for deprecation
 
- 
createCreate an instance ofRandomGeneratorbased on the algorithm chosen.- Returns:
- new instance of RandomGenerator.
 
- 
createCreate an instance ofRandomGeneratorbased on the algorithm chosen, and the providedseed. If theRandomGeneratordoesn't support instantiation through aseedof typelongthen this method throws anUnsupportedOperationException.- Parameters:
- seed- long random seed value.
- Returns:
- new instance of RandomGenerator.
- Throws:
- UnsupportedOperationException- if a- seedof type- longin not supported.
 
- 
createCreate an instance ofRandomGeneratorbased on the algorithm chosen, and the providedseed. If theRandomGeneratordoesn't support instantiation through aseedof typebyte[]then this method throws anUnsupportedOperationException.- Parameters:
- seed- byte array random seed value.
- Returns:
- new instance of RandomGenerator.
- Throws:
- UnsupportedOperationException- if a- seedof type- byte[]in not supported.
- NullPointerException- if seed is null.
 
 
-