Shuffle
Fisher\u2013Yates shuffle\nhttps://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\n\n\nclass Solution {\npublic:\n    Solution(int n_rows, int n_cols) {\n  
Fisher\u2013Yates shuffle\nhttps://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\n\n```\nclass Solution {\npublic:\n    Solution(int n_rows, int n_cols) {\n        \n        m = n_rows;\n        n = n_cols;\n        reset();\n    }\n    \n    vector<int> flip() {\n        \n        int k = rand() % (index + 1);\n        int val = k;\n        if (hash.count(k) != 0) val = hash[k];                               \n                        \n        if (hash.count(index) == 0) hash[k] = index;\n                               else hash[k] = hash[index];\n        --index;\n        \n        return {val / n, val % n};\n    }\n    \n    void reset() {\n        \n        index = m * n - 1;        \n        hash.clear();        \n    }\n    \n    int m;\n    int n;\n    unordered_map<int, int> hash;\n    int index;\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n_rows, n_cols);\n * vector<int> param_1 = obj.flip();\n * obj.reset();\n */\n ```\n\n
[]