How to get random point on the perimeter of a rectangle?

I need points for spawning enemies in my game.

Suppose I have a rectangle starting from (-50, -100) to (50, 100), how to get Vector2 coordinates of random points in that box perimeter?
I’ve tried choosing (random) a side first then get a random x or y axis in that line but that method feels so clunky and the results are bad, shorter sides have an equal chance to be choosen like the longer sides. (Makes the feeling of enemies more frequently spawns on the shorter sides)

Thanks for reading

Two ways spring to mind…

  1. Get a random number between 0 and the perimeter length, which is the distance that your random point will be from some specified corner. Use the side lengths to determine first which side the point is on, and then where on that side it is (this bit will be similar to what you’re already doing).

  2. Alternatively, do it the way you’re doing but weight the choice of a random side by the lengths of the sides.