Class RandomGeneratorExamples
java.lang.Object
net.jrodolfo.java_evolution.java17.RandomGeneratorExamples
Demonstrates the enhanced pseudo-random number generator API introduced in
Java 17.
Before Java 17, random-number APIs were less unified and algorithm selection was not as discoverable through one common abstraction.
Java 17 added the RandomGenerator interface and
RandomGeneratorFactory for selecting named algorithms. This gives
code a standard way to choose and discover pseudo-random number generators.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanalgorithmExists(String algorithm) Checks whether a named random generator algorithm exists.intboundedRandomValue(String algorithm, int bound) Creates a generator by algorithm name and produces a bounded value.
-
Constructor Details
-
RandomGeneratorExamples
public RandomGeneratorExamples()
-
-
Method Details
-
boundedRandomValue
Creates a generator by algorithm name and produces a bounded value.- Parameters:
algorithm- the random generator algorithm namebound- exclusive upper bound- Returns:
- a generated value between zero inclusive and bound exclusive
-
algorithmExists
Checks whether a named random generator algorithm exists.- Parameters:
algorithm- the algorithm name- Returns:
- whether the algorithm is available in this JDK
-