I first answer in a language agnostic way.
A very efficient way would be to keep a sequential list of all the possible positions (in your case 5x5=25 positions), use a single random choice in that list and then removes the position from the list. This saves you from the what to do when I hit a position I've already hitted
Python implementation :
First generate the list of positions :
positions = [ (i, j) for i in range(1,6) for j in range(1,6) ]
Then get a random position and remove it from the list
index = random.randrange(len(positions))
shotX, shotY = positions[index]
del positions[index]
Edit :
As a prove it should fork :
>>> import random
>>> positions = [ (i, j) for i in range(1,6) for j in range(1,6)]
>>> for i in range(25):
index = random.randrange(len(positions))
print positions[index]
del positions[index]
(5, 5)
(5, 4)
(1, 4)
(1, 2)
(3, 3)
(1, 1)
(4, 1)
(4, 4)
(5, 1)
(4, 2)
(2, 2)
(2, 4)
(2, 3)
(2, 1)
(3, 2)
(3, 5)
(1, 5)
(5, 3)
(5, 2)
(4, 3)
(4, 5)
(1, 3)
(3, 4)
(2, 5)
(3, 1)
>>> print positions
[]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…