Skip to content

Commit 72f7b11

Browse files
author
Nicolai Parlog
committed
Improve random generator demo
1 parent 8be75b3 commit 72f7b11

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/main/java/org/codefx/demo/java17/api/random/RandomGenerators.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ private static void simpleCreation() {
3737
// (for implemented algorithms, see Javadoc of java.util.random)
3838
var lxm = RandomGenerator.of("L128X128MixRandom");
3939
var xoshiro = RandomGenerator.of("Xoshiro256PlusPlus");
40+
41+
// even works with custom implementations by using the class' simple name
42+
var xkcd = RandomGenerator.of("Xkcd");
4043
}
4144

4245
private static void moreInterfaces() {

src/main/java/org/codefx/demo/java17/api/random/Xkcd.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import java.util.random.RandomGenerator.ArbitrarilyJumpableGenerator;
66

77
/*
8-
* It's possible to provide custom implementations of the generator interfaces that
9-
* get picked up by the generator factory API (including the `.of("name")` methods),
10-
* but that requires use of the JDK-internal annotation `@RandomGeneratorProperties`.
8+
* It's possible to provide custom implementations of the generator interfaces by
9+
* providing them as a service (see module declaration). Out of the box, that works
10+
* with `RandomGenerator::of` (and on the other generator interfaces).
1111
*
12-
* While this works, the integration mechanism isn't meant for public use.
12+
* By using the JDK-internal annotation `@RandomGeneratorProperties` (and possibly
13+
* opening this package to java.base), it also works with `RandomGeneratorFactory`,
14+
* but the integration mechanism isn't meant for public use.
1315
*/
1416

1517
@RandomGeneratorProperties(

0 commit comments

Comments
 (0)