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>You could also use random.sample to achieve this:</p>

<pre><code>from random import sample

GRID_TILES = 100
NUM_BOMBS = 5

indexes = sample(range(GRID_TILES * GRID_TILES), NUM_BOMBS)
BOMBS = [(i // GRID_TILES, i % GRID_TILES) for i in indexes]
</code></pre>

python python-3.x random