code: def sample(polygon, count, factor=1.5, max_iter=10):
      
      bounds = np.reshape(polygon.bounds, (2, 2))
      extents = bounds.ptp(axis=0)
  
      hit = []
      hit_count = 0
      per_loop = int(count * factor)
  
      for i in range(max_iter):
          # generate points inside polygons AABB
          points = np.random.random((per_loop, 2))
          points = (points * extents) + bounds[0]
  
          # do the point in polygon test and append resulting hits
          mask = vectorized.contains(polygon, *points.T)
          hit.append(points[mask])
  
          # keep track of how many points we've collected
          hit_count += len(hit[-1])
  
          # if we have enough points exit the loop
          if hit_count > count:
              break
  
      # stack the hits into an (n,2) array and truncate
      hit = np.vstack(hit)[:count]
  
      return hit
docs: Use rejection sampling to generate random points inside a
      polygon.
  
      Parameters
      -----------
      polygon : shapely.geometry.Polygon
                  Polygon that will contain points
      count   : int
                  Number of points to return
      factor  : float
                  How many points to test per loop
                  IE, count * factor
      max_iter : int,
                  Maximum number of intersection loops
                  to run, total points sampled is
                  count * factor * max_iter
  
      Returns
      -----------
      hit : (n, 2) float
             Random points inside polygon
             where n <= count