Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 28, 2019 00:46
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 parzibyte/d231def1bdda9100a62510de8e683ab2 to your computer and use it in GitHub Desktop.
Save parzibyte/d231def1bdda9100a62510de8e683ab2 to your computer and use it in GitHub Desktop.
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