Matrix, index out of range
<p>I've declared a matrix with the following code:</p>

<pre><code>matrix = [[' ' for x in range(x1)] for x in range(y1)]
</code></pre>

<p>But when I try to find a random element and change it's value with the following code:</p>

<pre><code>randomX = random.randint(0, x)
randomY = random.randint(0, y)
if matrix[randomX][randomY] == ' ':
    try:
        matrix[randomX][randomY] = 'G'
        scr.addstr(randomX, randomY, matrix[randomX][randomY])
        scr.refresh()
    except IndexError:
        return
</code></pre>

<p>I get an IndexError. I tried to just write some garbage code to exit the function if it runs in to an IndexError. It works once, then it still throws the error.</p>

<p>Note, x1 is the same as x in the function. Same goes with y1 and y.</p>

<p>Any clue what I'm doing wrong?</p>