Why using one Rand() failed 3 out of 35 test cases, while using 3 Rand() passed all?
Following is the version of using one rand() per pick, and it failed 3 test cases.\n\nclass Solution {\npublic:\n    vector<int> prefix_sum;\n    vector<vector<
Following is the version of using one rand() per pick, and it failed 3 test cases.\n```\nclass Solution {\npublic:\n    vector<int> prefix_sum;\n    vector<vector<int>> rects_vec;\n    int total = 0;\n    \n    Solution(vector<vector<int>>& rects) {\n        int cur = 0;\n        for (int i = 0; i < rects.size(); ++i) {\n            cur += (rects[i][2] - rects[i][0] + 1) * (rects[i][3] - rects[i][1] + 1);\n            prefix_sum.push_back(cur);\n        }\n        rects_vec = rects;\n        total = cur;\n    }\n    \n    vector<int> pick() {\n        int l = 0, r = prefix_sum.size() - 1, mid = 0;\n        int rand_num = rand();\n        int target = (rand_num % total) + 1;\n\t\t\n        while (l <= r) {\n            mid = l + (r - l) / 2;\n            if (prefix_sum[mid] < target) l = mid + 1;\n            else r = mid - 1;\n        }\n \n        return {rand_num % (rects_vec[l][2] - rects_vec[l][0] + 1) + rects_vec[l][0],\n                rand_num % (rects_vec[l][3] - rects_vec[l][1] + 1) + rects_vec[l][1]};\n    }\n};\n```\n\nThen I changed rand_num to rand(), it passes all the test cases, what could be the reason??? Really confused\n```\nclass Solution {\npublic:\n    vector<int> prefix_sum;\n    vector<vector<int>> rects_vec;\n    int total = 0;\n    \n    Solution(vector<vector<int>>& rects) {\n        int cur = 0;\n        for (int i = 0; i < rects.size(); ++i) {\n            cur += (rects[i][2] - rects[i][0] + 1) * (rects[i][3] - rects[i][1] + 1);\n            prefix_sum.push_back(cur);\n        }\n        rects_vec = rects;\n        total = cur;\n    }\n    \n    vector<int> pick() {\n        int l = 0, r = prefix_sum.size() - 1, mid = 0;\n        int rand_num = rand();\n        int target = (rand_num % total) + 1;\n        \n        while (l <= r) {\n            mid = l + (r - l) / 2;\n            if (prefix_sum[mid] < target) l = mid + 1;\n            else r = mid - 1;\n        }\n \n        return {rand() % (rects_vec[l][2] - rects_vec[l][0] + 1) + rects_vec[l][0],\n                rand() % (rects_vec[l][3] - rects_vec[l][1] + 1) + rects_vec[l][1]};\n    }\n};\n```
['C']