code: def get_random_condcount(mode):
      
      cutofftime = datetime.timedelta(minutes=-CONFIG.getint('Server Parameters',
                                                             'cutoff_time'))
      starttime = datetime.datetime.now() + cutofftime
  
      try: 
          conditions = json.load(open(os.path.join(app.root_path, 'conditions.json')))
          numconds = len(conditions.keys())
          numcounts = 1
      except IOError as e:
          numconds = CONFIG.getint('Task Parameters', 'num_conds')
          numcounts = CONFIG.getint('Task Parameters', 'num_counters')
  
      participants = Participant.query.\
          filter(Participant.codeversion == \
                 CONFIG.get('Task Parameters', 'experiment_code_version')).\
          filter(Participant.mode == mode).\
          filter(or_(Participant.status == COMPLETED,
                     Participant.status == CREDITED,
                     Participant.status == SUBMITTED,
                     Participant.status == BONUSED,
                     Participant.beginhit > starttime)).all()
      counts = Counter()
      for cond in range(numconds):
          for counter in range(numcounts):
              counts[(cond, counter)] = 0
      for participant in participants:
          condcount = (participant.cond, participant.counterbalance)
          if condcount in counts:
              counts[condcount] += 1
      mincount = min(counts.values())
      minima = [hsh for hsh, count in counts.iteritems() if count == mincount]
      chosen = choice(minima)
      #conds += [ 0 for _ in range(1000) ]
      #conds += [ 1 for _ in range(1000) ]
      app.logger.info("given %(a)s chose %(b)s" % {'a': counts, 'b': chosen})
  
      return chosen
docs: HITs can be in one of three states:
          - jobs that are finished
          - jobs that are started but not finished
          - jobs that are never going to finish (user decided not to do it)
      Our count should be based on the first two, so we count any tasks finished
      or any tasks not finished that were started in the last cutoff_time
      minutes, as specified in the cutoff_time variable in the config file.
  
      Returns a tuple: (cond, condition)