With Shapely: http://toblerity.org/shapely/manual.html#polygons
The polygon
in code below must be Polygon object.
from shapely import Point
def generate_random(number, polygon):
list_of_points = []
minx, miny, maxx, maxy = polygon.bounds
counter = 0
while counter < number:
pnt = Point(random.uniform(minx, maxx), random.uniform(miny, maxy))
if polygon.contains(pnt):
list_of_points.append(pnt)
counter += 1
return list_of_points