[Python] Readable & Clean Solution with Binary Search
\nimport random\nclass Solution:\n\n    def numberOfPoints(self, rect):\n        x1, y1, x2, y2 = rect\n        return ((abs(x1-x2)+1) * (abs(y1-y2)+1)) \n    \
```\nimport random\nclass Solution:\n\n    def numberOfPoints(self, rect):\n        x1, y1, x2, y2 = rect\n        return ((abs(x1-x2)+1) * (abs(y1-y2)+1)) \n    \n    def sampleFromRect(self, rect):\n        x1, y1, x2, y2 = rect\n        x = random.randint(x1, x2) \n        y = random.randint(y1, y2) \n        return [x, y]\n    \n    def chooseRect(self):\n        x = random.randint(0,self.n_points)\n        left  = 0\n        right = len(self.rects) - 1\n        while left < right:\n            mid = (left + right) // 2\n            if x < self.prefix_sum[mid] :\n                right = mid\n            else:\n                left = left +1\n        return self.rects[left]\n            \n    def generatePrefixSum(self):\n        self.prefix_sum = [0] * len(self.rects)\n        self.prefix_sum[0] = self.numberOfPoints(self.rects[0])   \n        for i in range(1,len(self.rects)):\n            self.prefix_sum[i] = self.prefix_sum[i-1] + self.numberOfPoints(self.rects[i])   \n        self.n_points = self.prefix_sum[-1]\n        print(self.prefix_sum )\n    \n    \n    def __init__(self, rects: List[List[int]]):\n        self.rects = rects\n        self.generatePrefixSum()\n\n    def pick(self) -> List[int]:\n        rect = self.chooseRect()\n        return self.sampleFromRect(rect)\n\n```
[]