```
class Solution {
int[] arr;
public Solution(int[] nums) {
this.arr = nums;
}
public int pick(int target) {
int count = 0;
int result = -1;
for (int i = 0;i<this.arr.length;i++){
if (target == this.arr[i]){
count++;
Random rand = new Random();
int r = rand.nextInt(count);
if (r==count -1){
result = i;
}
}
}
return result;
}
}
```