Any, I think I just had an idea too. Might be bonkers though ;)
first generate randon number 1-4.
1 = top edge
2 = right edge
3 = bott... etc
if top edge then y=0, x= random (0, xmax)
if bottom edge then y = ymax, x= random (0, xmax)
and vice versa for left and right?