C++ Fisher-Yates Shuffle with explanation
\n\nclass Solution {\npublic:\n    \n    int cnt;\n    int cols;\n    int rows;\n    unordered_map<int, int> hash;\n    \n    Solution(int n_rows, int n_cols) :
\n```\nclass Solution {\npublic:\n    \n    int cnt;\n    int cols;\n    int rows;\n    unordered_map<int, int> hash;\n    \n    Solution(int n_rows, int n_cols) : rows(n_rows), cols(n_cols), cnt(n_rows * n_cols){\n        \n    }\n    \n    vector<int> flip() {\n        \n        int index = rand() % (cnt--);\n        int i = hash.count(index) ? hash[index] : index;\n        hash[index] = hash.count(cnt) ? hash[cnt] : cnt;\n        \n        return {i / cols, i % cols};\n        \n    }\n    \n    void reset() {\n        \n        cnt = rows * cols;\n        hash.clear();\n        \n    }\n};\n```\n\nTake a example:\n1. If we have a matrix with size(2 * 3)\n2. We get the 1d index = [0,1,2,3,4,5]\n\n![image](https://assets.leetcode.com/users/images/16b6ffb6-7fe7-4430-a160-077b911c0e11_1608474432.5446725.png)\n\n\n\n
[]