-
-
Save parzibyte/d231def1bdda9100a62510de8e683ab2 to your computer and use it in GitHub Desktop.
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
import java.util.concurrent.ThreadLocalRandom; | |
class Main { | |
public static void main(String[] args) { | |
for (int x = 1; x <= 5; x++) { | |
System.out.printf("Número aleatorio entre 2, 50: %d\n", numeroAleatorioEnRango(2, 50)); | |
System.out.printf("Número aleatorio entre 100, 200: %d\n", numeroAleatorioEnRango(100, 200)); | |
System.out.printf("Número aleatorio entre 1, 5: %d\n", numeroAleatorioEnRango(1, 5)); | |
System.out.printf("Número aleatorio entre 1500, 2000: %d\n", numeroAleatorioEnRango(1500, 2000)); | |
System.out.printf("Número aleatorio entre 1, 5268: %d\n", numeroAleatorioEnRango(1, 5268)); | |
System.out.printf("Número aleatorio entre 20, 55: %d\n", numeroAleatorioEnRango(20, 55)); | |
System.out.printf("Número aleatorio entre 17, 86: %d\n", numeroAleatorioEnRango(17, 86)); | |
} | |
} | |
public static int numeroAleatorioEnRango(int minimo, int maximo) { | |
// nextInt regresa en rango pero con límite superior exclusivo, por eso sumamos 1 | |
return ThreadLocalRandom.current().nextInt(minimo, maximo + 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment