Depends on how you are spawning randomly to begin with. If it is random x, y coordinate, you can add a condition to check the distance of that coordinate to the player. If it is within a certain range, pick a new coordinate, else spawn at that coordinate.