The space complexity is O(1).

```
class Solution(object):
def __init__(self, nums):
"""
:type nums: List[int]
:type numsSize: int
"""
self.nums = nums
def pick(self, target):
"""
:type target: int
:rtype: int
"""
import random
m = 0
temp = 0
for idx, num in enumerate(self.nums):
if num == target:
t = random.random()
if t > m:
temp = idx
m = t
return temp
```