Java AC Solution, call Least times of Random.nextInt() function
Only call once every time\nJava\nclass Solution {\n\n    Map<Integer, Integer> map;\n    int rows, cols, total;\n    Random rand;\n    \n    public Solution(int
Only call once every time\n```Java\nclass Solution {\n\n    Map<Integer, Integer> map;\n    int rows, cols, total;\n    Random rand;\n    \n    public Solution(int n_rows, int n_cols) {\n        map = new HashMap<>();\n        rand = new Random();\n        rows = n_rows; \n        cols = n_cols; \n        total = rows * cols;\n    }\n    \n    public int[] flip() {\n        int r = rand.nextInt(total--);\n        int x = map.getOrDefault(r, r);\n        map.put(r, map.getOrDefault(total, total));\n        return new int[]{x / cols, x % cols};\n    }\n    \n    public void reset() {\n        map.clear();\n        total = rows * cols;\n    }\n}\n```
[]