public static int[] uniqueRandomElements (int size) { int[] a = new int[size]; for (int i = 0; i < size; i++) { a[i] = (int)(Math.random()*10);
Input your size and get list of random unique numbers using Collections.
public static ArrayList noRepeatShuffleList(int size) { ArrayList arr = new ArrayList<>(); for (int i = 0; i < size; i++) { arr.add(i); } Collections.shuffle(arr); return arr; }
Elaborating Karthik's answer.