def choose_promo(promo_list):
 promo_range = []
 total_views_needed = 0
 for promo in promo_list:
  promo_range.append([total_views_needed, (total_views_needed + promo.views_needed_today()), promo])
  total_views_needed += promo.views_needed_today()
 choice = random.randint(0, total_views_needed)
 for range_list in promo_range:
  if (range_list[0] <= choice <= range_list[1]):
   return range_list[2]
 return None

def choose_promo ( promo_list ) : promo_range = [ ] total_views_needed = 0 for promo in promo_list : promo_range . append ( [ total_views_needed , ( total_views_needed + promo . views_needed_today ( ) ) , promo ] ) total_views_needed += promo . views_needed_today ( ) choice = random . randint ( 0 , total_views_needed ) for range_list in promo_range : if ( range_list [ 0 ] <= choice <= range_list [ 1 ] ) : return range_list [ 2 ] return None
this is the algorithm to pick which promo to show .