这个可以应用在很多场合的,你猜?
import random time_seconds = 18000 time_seconds_float = 1800 number = 500 print "this range of limit is between %s and %s" % (time_seconds, time_seconds + time_seconds_float) while True: time_list = [random.randint(10, 70) for i in range(500)] print 'sum of time_list:', sum(time_list) if sum(time_list) > time_seconds and sum(time_list) < time_seconds + time_seconds_float: break print "length of time_list:",len(time_list) print time_list