Python | Reservoir Sampling | O(1) | Easy Solution
```\nfrom collections import defaultdict\nclass Solution:\n\n    def init(self, m: int, n: int):\n        self.m = m\n        self.n = n\n        self.reset()\n
```\nfrom collections import defaultdict\nclass Solution:\n\n    def __init__(self, m: int, n: int):\n        self.m = m\n        self.n = n\n        self.reset()\n\n    def flip(self) -> List[int]:\n        i = randint(0, self.r)\n        if self.nums[i] == -1:\n            self.nums[i] = i\n        if self.nums[self.r] == -1:\n            self.nums[self.r] = self.r\n        self.nums[i], self.nums[self.r] = self.nums[self.r], self.nums[i]\n        self.r -= 1\n        num = self.nums[self.r+1]\n        return (num//self.n, num%self.n)\n\n    def reset(self) -> None:\n        self.r = self.m*self.n-1\n        self.nums = defaultdict(lambda : -1)
['Python']