Randomly generating coordinates inside a bounded region

Like any problem, there are many ways to solve it, the first thing came into my mind is

  1. Let's call this "geographic area" a polygon.
  2. Find the bounding box of the polygon (easy, just find maxX maxY minX minY).
  3. Generate random coordinate inside the bounding box x=rand()%(maxX-minX)+minX (and same for Y)
  4. Test that the coordinate is inside the polygon, there are many solutions to this problem and they are implemented in any given language so you don't have to implement it by yourself. Here is an implementation in C/C++ (it is easy to change it to any other language) : Point in Polygon Algorithm

http://en.wikipedia.org/wiki/Point_in_polygon

Edit : As Jan Dvorak suggested, it might be problematic to use it technique on huge areas, i believe that if your polygon is close to the equator and his size is less the 100km, it will work just fine.

Also you will run into problems if you are near the 180° line because right next to it is the -180°.