Check for duplicates in a randomly generated list and replace them
<p>I am making a minesweeper game with randomly generated bombs. Yet at times I have found that there are duplicates in my list of coordinates of bombs. How do I check for duplicates in a list and replace them with other randomised coordinates.</p>

<pre><code>from random import randint

def create_bombpos():
    global BOMBS, NUM_BOMBS, GRID_TILES
    for i in range(0, NUM_BOMBS):
        x = randint(1, GRID_TILES)
        y = randint(1, GRID_TILES)
        BOMBS.append((x, y))
    print(BOMBS)
</code></pre>

<p>The user can decide how big the board is by input of <code>GRID_TILES</code>.
If they input 5, the board will be 5x5. The ammount of bombs is: </p>

<pre><code>GRID_TILES * GRIDTILES / 5
</code></pre>

<p>Use a python set for this, it will automatically check for duplicates and simply ignore every entry that already is in the list.
I also think the runtime is much better than using a list and checking for duplicates manually.</p>

<p>Link: <a href="https://docs.python.org/2/library/sets.html" rel="nofollow">https://docs.python.org/2/library/sets.html</a></p>

python python-3.x random