Skip to content

Instantly share code, notes, and snippets.

@TGITS
Last active May 20, 2023 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TGITS/ff22c4669860d5b091731c465d88a456 to your computer and use it in GitHub Desktop.
Save TGITS/ff22c4669860d5b091731c465d88a456 to your computer and use it in GitHub Desktop.
Script JShell montrant l'utilisation de nullRate() lors de la génération de séquences avec des données factices
//DEPS net.datafaker:datafaker:1.9.0
/**
* Pour executer avec JBang : jbang NullRateExample.jsh
* <p>
* Pour exécuter sous JShell :
* jshell --class-path .;.\lib\datafaker-1.9.0.jar
* /open NullRateExample.jsh
*/
import net.datafaker.Faker;
import java.util.List;
import java.util.stream.Stream;
Faker faker = new Faker();
List<String> isbns = faker.<String>collection().suppliers(() -> faker.code().isbn10(true)).nullRate(0.4).len(10).generate();
System.out.println("Printing some ISBNs - Possibly some null values :");
isbns.forEach(System.out::println);
// With a null rate of 1, only null values
Stream<String> nulls = faker.<String>stream().suppliers(() -> faker.code().isbn10(true)).nullRate(1.0).len(10).generate();
System.out.println("\nSo much null values !");
nulls.forEach(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment