Array of unique random integers in java
// n : size of array
// no : elements in array will be less than no
// no>=n
private int[] uniqueIntArrray(int n,int no) {
int flag = 0; int ar[] = new int[n]; for (int i = 0; i < n; ) { flag = 0; int x = (int) (Math.random() * no); for (int j = 0; j < i; j++) { if (x == ar[j]) { flag = 1; } } if (flag == 1) { } else { ar[i] = x; i++; } } return ar; }
Comments