If we have `int[] nums = [1,2,3,1,1,1,1,1]`

, using `r.nextInt(n)`

will give us a random int between `[0, n)`

(exclusive), so each number in nums has 1/n probability to be returned.

Thus, numbers equal to target share the same probability.

```
public class Solution {
int[] nums;
Random r;
public Solution(int[] nums) {
this.nums = nums;
r = new Random();
}
public int pick(int target) {
int size = nums.length;
int i = r.nextInt(size);
while (nums[i] != target) {
i = r.nextInt(size);
}
return i;
}
}
```