I tried to write a program that would select teams to manage randomly,however when I run it I get the same 4 teams rather than different ones each time ?
I tried to make it so that each time I generate a random number it would go into an array.Then I would check against that array to see if the number had been used before.
Any help or advice would be appreciated. Thanks!
import java.util.*;
class Start {
static String[] places = {"Man Utd", "Arsenal", "Aston Villa", "Chelsea",
"Everton", "Fulham", "Liverpool", "Man City", "Newcastle", "Norwich",
"QPR", "Reading", "Southampton", "Stoke", "Sunderland", "Swansea",
"Spurs", "West Brom", "West ham", "Wigan"};
static int[] NA = {21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21};
static Random rand = new Random();
static int RandInt = 0;
static boolean x = false;
static boolean p = false;
static int player = 1;
public static void main(String[] args) {
while (x != true) {
RandInt = rand.nextInt(places.length);
for (int k = 0; k <= NA.length; k++) {
while (p != true) {
if (RandInt == NA[k]) {
RandInt = rand.nextInt(places.length);
} else {
p = true;
NA[k] = RandInt;
}
}
System.out.println("player " + player + " is managing " + places[RandInt]);
player++;
p = false;
if (player >= 5) {
x = true;
System.exit(0);
}
}
}
}
}