Through HashMap
\nclass Solution {\n     HashMap<Integer,Integer>map;\n    Random r;\n    int upperlimit;\n    public Solution(int n, int[] blacklist) {\n        upperlimit = n
```\nclass Solution {\n     HashMap<Integer,Integer>map;\n    Random r;\n    int upperlimit;\n    public Solution(int n, int[] blacklist) {\n        upperlimit = n-blacklist.length;\n        map = new HashMap<>();\n        r = new Random();\n        for(int k: blacklist)\n        {\n            map.put(k,-1);\n        }\n        int j = n-1;\n        for(int k : blacklist)\n        {\n           if(k<upperlimit)\n           {\n                while(map.containsKey(j))\n                {\n                    j--;\n                }\n               map.put(k,j);\n               j--;\n           }\n            \n        }\n        \n        \n    }\n    \n    public int pick() {\n        int val = r.nextInt(upperlimit);\n        if(map.containsKey(val))\n        {\n            return map.get(val);\n        }\n        return val;\n        \n    }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(n, blacklist);\n * int param_1 = obj.pick();\n */\n```
['Java']