GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing javaevolved.dev — RandomGenerator interface | java.evolved
Security
Intermediate
RandomGenerator interfaceUse the RandomGenerator interface to choose random number algorithms by name without coupling to a specific class. Code Comparison
✕ Java 8
// Hard-coded to one algorithm
Random rng = new Random();
int value = rng.nextInt(100);
// Or thread-local, but still locked in
int value = ThreadLocalRandom.current()
.nextInt(100);
✓ Java 17+
// Algorithm-agnostic via factory
var rng = RandomGenerator.of("L64X128MixRandom");
int value = rng.nextInt(100);
// Or get a splittable generator
var rng = RandomGeneratorFactory
.of("L64X128MixRandom").create();
See a problem with this code? Let us know.
Why the modern way wins
🔧
Algorithm-agnosticChoose the best RNG algorithm by name without changing code structure. ⚡
Better algorithmsAccess to modern LXM generators with superior statistical properties. 🔗
Unified APIOne interface covers Random, ThreadLocalRandom, SplittableRandom, and more. Old Approach
new Random() / ThreadLocalRandom
Modern Approach
RandomGenerator factory
Since JDK
17
Difficulty
Intermediate
JDK Support
RandomGenerator interface
Available
Available since JDK 17 (September 2021, JEP 356). How it works
JDK 17 introduced RandomGenerator as a common interface for all RNG implementations. Instead of hard-coding new Random() or ThreadLocalRandom, you can select algorithms by name via a factory, making it easy to swap between algorithms optimized for different use cases (speed, statistical quality, splittability). Related Documentation
Proof
Related patterns
Security
Beginner
Strong random generationJava 8
// Default algorithm — may not be
// the strongest available
SecureRandom random =
new SecureRandom();
byte[] bytes = new byte[32];
random.nextBytes(bytes);
Java 9+
// Platform's strongest algorithm
SecureRandom random =
SecureRandom.getInstanceStrong();
byte[] bytes = new byte[32];
random.nextBytes(bytes);
JDK 9+
→
Security
Advanced
Key Derivation FunctionsJava 8
SecretKeyFactory factory =
SecretKeyFactory.getInstance(
"PBKDF2WithHmacSHA256");
KeySpec spec = new PBEKeySpec(
password, salt, 10000, 256);
SecretKey key =
factory.generateSecret(spec);
Java 25
var kdf = KDF.getInstance("HKDF-SHA256");
SecretKey key = kdf.deriveKey(
"AES",
KDF.HKDFParameterSpec
.ofExtract()
.addIKM(inputKey)
.addSalt(salt)
.thenExpand(info, 32)
.build()
);
JDK 25+
→
Concurrency
Beginner
Virtual threadsJava 8
Thread thread = new Thread(() -> {
System.out.println("hello");
});
thread.start();
thread.join();
Java 21+
Thread.startVirtualThread(() -> {
IO.println("hello");
}).join();
JDK 21+
→
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |