I'm trying to write a method that gets a list of numbers from 1 to 10 where there will be no duplicates. Also the member must not be zero. However, after many attempts I failed to solve the problem, this is my code:
public ArrayList<Integer> dobijNiz() {
int min = 1;
int max = 10;
ArrayList<Integer> lista = new ArrayList<Integer>();
Random random = new Random();
for (int i = 0; i < 11; i++) {
int broj = random.nextInt((max - min) + 1) + min;
lista.add(broj);
}
System.out.println(lista);
return lista;
}
Output:
[2, 3, 3, 3, 4, 6, 10, 8, 2, 7, 9]
I forgot to say that Collections.shuffle doesn't work