Least number of Random call using Set with explanation
The algorithm is very similar to this https://en.wikipedia.org/wiki/Fisher\u2013Yates_shuffle but instead of keeping track of the full array we only keep track 
The algorithm is very similar to this https://en.wikipedia.org/wiki/Fisher\u2013Yates_shuffle but instead of keeping track of the full array we only keep track of the numbers we have already flipped. Example n_rows = 2 n_columns=3 , start counting by 1 for ease, 2*3=6\n\nmax 6  | set <>\nGenerate randomly a number between 1-6, generated 6, 6 not in set flip it and return it\n\nmax 5 | set <6>\nGenerate randomly a number between 1-5, generated 4, 4 not in set flip it and return it\n\nmax 4 | set <4,6>\nGenerate randomly a number between 1-4, generated 4, 4 is already in set\nNow if we had the full array in memory the array would look like this : 1,2,3,5 therefore we would return the item 5 since that item is in position 4. Furthermore since max =4 and generated =4 it means the item returned would be the first item encountered starting by the end of the array. So we can start from number 6...1 and find the first item not already in set. 6 is already in the set so we ignore it, then go to 5, 5 is not in the set so we add it, flip it and return it.\n\n\n\n```\nclass Solution {\n\n    Set<Integer> used;\n    Random rand = new Random();\n    int n_rows;\n    int n_cols;\n    \n    public Solution(int n_rows, int n_cols) {\n        used = new HashSet<>();\n        this.n_rows = n_rows;\n        this.n_cols = n_cols;\n    }\n    \n    public int[] flip() {\n        int randomFlip = rand.nextInt(n_rows * n_cols - used.size()); \n        if(used.contains(randomFlip)){\n            int i = n_rows * n_cols - 1;\n            int effective = n_rows * n_cols - used.size() - randomFlip;\n\n            while(effective != 0){\n                if(!used.contains(i)) effective--;\n                i--;\n            }\n\n            randomFlip = i+1;\n            \n        }\n        used.add(randomFlip);\n        int ret[] = new int[2];\n        ret[0] =  randomFlip / n_cols;\n        ret[1] =  randomFlip % n_cols;\n        return ret;\n    }\n    \n    public void reset() {\n        used = new HashSet<>();\n    }\n}
[]