Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 24, 2020 17:50
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/e481a1de1ba4e3f36d37e46782a56dc4 to your computer and use it in GitHub Desktop.
Save parzibyte/e481a1de1ba4e3f36d37e46782a56dc4 to your computer and use it in GitHub Desktop.
import java.util.concurrent.ThreadLocalRandom;
public class Main {
// https://parzibyte.me/blog
public static void main(String[] args) {
String[] juegos = {"Horizon Zero Dawn", "Dark Souls III", "Cuphead", "Doom 2016", "Halo MCC", "Bioshock"};
int indiceAleatorio = numeroAleatorioEnRango(0, juegos.length - 1);
String juegoAleatorio = juegos[indiceAleatorio];
System.out.printf("Un juego aleatorio: %s", juegoAleatorio);
}
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