I create mathod random() for random a string.
When run this code below sometimes word at random are duplicate as:
word: ANT
word: ANT
I require random word and not duplicate.
How to solve this problem?
class Test{
static String[] STRING = {"ANT","COW","HAM","BAT","DOG","CAT","MIN","MAX","JOB","CAR","WIN"};
static final Random random = new Random();
//
//
random(STRING);
public static void random(String[] STRING){
for (int i = 0; i < 1;i++) {
num = random.nextInt(STRING.length);
System.out.println("random value: "+num);
System.out.println("word : "+STRING[num]);
}
}
}