java 7+ public static int[] generateArr(int size, int range) { int n = ThreadLocalRandom.current().nextInt(1, size); int[] arr = new int[n]; for (int i = 0; i < arr.length; i++) { arr[i] = ThreadLocalRandom.current().nextInt(1, range + 1); } return arr; }