RandomGeneratorFactory Picks Seeded Algorithms
List built-in generator algorithms, select one by name, and prove same-seed reproducibility so tests and replays stay deterministic.
Code
import java.util.random.RandomGeneratorFactory;
public class DicePicker {
public static void main(String[] args) {
// list the JVM's built-in random number generator algorithms (deprecated ones skipped)
RandomGeneratorFactory.all()
.filter(factory -> !factory.isDeprecated())
.forEach(factory ->
System.out.println(factory.name() + " stateBits=" + factory.stateBits()));
// select an algorithm by name: an unknown name throws IllegalArgumentException
RandomGeneratorFactory<?> factory = RandomGeneratorFactory.of("L64X128MixRandom");
// the same seed reproduces the same sequence: the basis for regression tests and incident replay
var genA = factory.create(20261114L);
var genB = factory.create(20261114L);
for (int i = 0; i < 3; i++) {
System.out.println("draw: " + genA.nextInt(100) + " / " + genB.nextInt(100));
}
}
}How the snippet works
RandomGeneratorFactory Picks Seeded Algorithms reduces to the class DicePicker and the function main.
The loop for (int i = 0; i < 3; i++) is the only repeated construct.
Applying it
The demo output is labeled (draw:), so every printed line maps back to its originating operation.
Statements that matter
.filter(factory -> !factory.isDeprecated())
.forEach(factory ->
System.out.println(factory.name() + " stateBits=" + factory.stateBits()));
Interactive Tools for This Topic
Big-O Complexity VisualizerVisualize and compare algorithm time complexities like O(1), O(log n), O(n), O(n log n), and O(n²). Plot growth curves to understand performance scaling at a glance.Passphrase GeneratorGenerate memorable multi-word passphrases from a fixed 150-word list with crypto randomness, separators, and capitalization options.Password GeneratorGenerate random passwords from selectable character classes using crypto.getRandomValues with rejection sampling and class guarantees.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
FAQ
- What does RandomGeneratorFactory Picks Seeded Algorithms print when run?
- Running the file directly is enough — expect labeled output lines such as `draw:`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.