Python swap solution
\nclass Solution(object):\n\n    def __init__(self, N, blacklist):\n        """\n        :type N: int\n        :type blacklist: List[int]\n        """\n        
```\nclass Solution(object):\n\n    def __init__(self, N, blacklist):\n        """\n        :type N: int\n        :type blacklist: List[int]\n        """\n        self.bmap = {}\n        for num in blacklist:\n            if num <= N-1:\n                self.bmap[num] = -1\n\n        self.M = N - len(self.bmap)\n        i = N-1\n        for bn in self.bmap:\n            while i in self.bmap:\n                i -= 1\n            if bn < self.M:\n                self.bmap[bn] = i\n                i -= 1\n\n    def pick(self):\n        """\n        :rtype: int\n        """\n        idx = random.randint(0, self.M-1)\n\n        if idx not in self.bmap:\n            return idx\n        else:\n            return self.bmap[idx]\n```
[]