Last active
May 20, 2023 09:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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