I have a problem with random and arrays. I have a list empty list and I want to add 8 some random values, but I don't want to some values was the same. To get some random value I use this code:
for (int i = 0; i < 8; i++) {
round = random.nextInt(31);
while (temp.get(round).equals(mix)) {
round = random.nextInt(31);
}
mix.add(temp.get(round));
}
temp is list with 32 objects and mix is my list where I want to add 8 random values. But when I random some values sometimes I get the same values. How I can get random values but without duplicates?