Based on

https://discuss.leetcode.com/topic/58297/share-c-o-n-time-solution

```
class Solution {
public:
vector<int> n;
Solution(vector<int> nums)
{
n = nums;
}
int pick(int target)
{
int count = 0, res = -1;
for (int i = 0; i < n.size(); ++i)
if(n[i] == target && (!(rand()%++count))) res=i;
return res;
}
};
```