From 1cc8ed180e38babc09ec6dfad2a24696dc8b1405 Mon Sep 17 00:00:00 2001 From: Fabio Lima Date: Mon, 15 Nov 2021 07:56:11 -0300 Subject: [PATCH] Update README.md --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1852b42..5deaa98 100644 --- a/README.md +++ b/README.md @@ -205,14 +205,32 @@ Use a `UlidFactory` with `java.util.Random`: // use a `java.util.Random` instance for fast generation UlidFactory factory = UlidFactory.newInstance(new Random()); Ulid ulid = factory.create(); + +// use the factory ``` -Use a `UlidFactory` with a random generator of your choice: +Use a `UlidFactory` with a random generator of your choice inside of a `Supplier`: ```java // use a random supplier that returns an array of 10 bytes AwesomeRandom awesomeRandom = new AwesomeRandom(); // a hypothetical RNG UlidFactory factory = UlidFactory.newInstance(() -> awesomeRandom.nextBytes(Ulid.RANDOM_BYTES)); + +// use the factory +Ulid ulid = factory.create(); +``` + +Use a `UlidFactory` with `ThreadLocalRandom` inside of a `Supplier`: + +```java +// use a random supplier that returns an array of 10 bytes +UlidFactory factory = UlidFactory.newInstance(() -> { + final byte[] bytes = new byte[Ulid.RANDOM_BYTES]; + ThreadLocalRandom.current().nextBytes(bytes); + return bytes; +}); + +// use the factory Ulid ulid = factory.create(); ```