Last active
February 15, 2022 14:17
-
-
Save TGITS/caf144bad442426351d41bf79745c4d3 to your computer and use it in GitHub Desktop.
Script (à exécuter sous JShell) d'exemple de création d'un générateur de nombre aléatoire
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
//A exécuter sous JShell : /open RandomGenerationExampleScript.java | |
//Penser à configurer la console en UTF-8 avec chcp 65001 avant de lancer jshell | |
import java.util.random.RandomGenerator; | |
import java.util.random.RandomGeneratorFactory; | |
//Utilisation du générateur par défaut | |
var randomGeneratorDefault = RandomGenerator.getDefault(); | |
System.out.println("Génération d'une valeur aléatoire booléenne : " + randomGeneratorDefault.nextBoolean()); | |
System.out.println("Génération d'une valeur aléatoire entière de type 'int' : " + randomGeneratorDefault.nextInt()); | |
System.out.println("Génération d'une valeur aléatoire entière de type 'long' : " + randomGeneratorDefault.nextLong()); | |
System.out.println("Génération d'une valeur aléatoire réelle de type 'double' : " + randomGeneratorDefault.nextDouble()); | |
System.out.println("Génération d'une flux de 5 valeurs entières : "); | |
randomGeneratorDefault.ints(5).forEach(System.out::println); | |
System.out.println("Génération d'une flux de 5 valeurs réelles : "); | |
randomGeneratorDefault.doubles(5).forEach(System.out::println); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment