code: def throw_random_intervals( lengths, regions, save_interval_func=None, allow_overlap=False ):
      
      # Copy regions
      regions = [( x[1]-x[0], x[0], x ) for x in regions]
      # Sort (long regions first)    
      regions.sort()
      regions.reverse()
      # Throw
      if (save_interval_func != None):
          throw_random_private( lengths, regions, save_interval_func, allow_overlap )
          return
      else:
          intervals = []
          save_interval_func = lambda s, e, rgn: intervals.append( overwrite_start_end ( s, e, rgn ) )
          throw_random_private( lengths, regions, save_interval_func, allow_overlap )
          return intervals
docs: Generates a set of non-overlapping random intervals from a length 
      distribution.
      
      `lengths`: list containing the length of each interval to be generated.
                 We expect this to be sorted by decreasing length to minimize
                 the chance of failure (MaxtriesException) and for some
                 performance gains when allow_overlap==True and there are
                 duplicate lengths.
      `regions`: A list of regions in which intervals can be placed.  Elements
                 are tuples or lists of the form (start, end, ...), where ...
                 indicates any number of items (including zero).
      `save_interval_func`: A function accepting three arguments which will be 
                            passed the (start,stop,region) for each generated 
                            interval, where region is an entry in the regions
                            list.  If this is None, the generated intervals will
                            be returned as a list of elements copied from the
                            region with start and end modified.