The issue you're having is because you're looping through possible coords
for x = 0; x < maxX; x++
for y = 0; y < maxY; y++
You have two options.
#1: Randomize the direction you start searching from (top left, bottom left, top right, bottom right)
#2: Search from the center outwards in a spiral formation (will solve the need for your duplicated code)
Here's some discussions on spiral searching