Update README.md

This commit is contained in:
Fabio Lima 2021-11-15 07:56:11 -03:00 committed by GitHub
parent f384d26c93
commit 1cc8ed180e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -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<byte[]>`:
```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<byte[]>`:
```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();
```