-
-
Save parzibyte/e481a1de1ba4e3f36d37e46782a56dc4 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; | |
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