def test_randint(self): self.assertEqual(utility.randint(0), 0) self.assertEqual(utility.randint(0, 0), 0) self.assertEqual(utility.randint(9, 9), 9) number = self.assertTrue(utility.randint(1, 2)) self.assertTrue(0 < number < 3)
def test_randint(self): self.assertEqual(utility.randint(0), 0) self.assertEqual(utility.randint(0, 0), 0) self.assertEqual(utility.randint(9, 9), 9) number = self.assertTrue(utility.randint(1, 2)) self.assertTrue(number>0 and number<3)
def do_statspollute(dbfile): # source gl_database = create_database("sqlite:%s" % dbfile) source_store = Store(gl_database) stats = source_store.find(models.Stats) counter = 0 for s in stats: source_store.remove(s) counter += 1 print "removed %d entry in stats" % counter counter = 0 # 21 days in the past for past_hours in xrange(24 * 7 * 3): past_hours += 4 when = utc_past_date(hours=past_hours) newstat = models.Stats() newstat.freemb = randint(1000, 1050) newstat.year = when.isocalendar()[0] newstat.week = when.isocalendar()[1] level = round((randint(0, 1000) / 240.0), 1) - 2 def random_pollution(): return int(randint(0,11) + (5 * level)) activity_fake = { 'successfull_logins': random_pollution(), 'failed_logins': random_pollution(), 'started_submissions': random_pollution(), 'completed_submissions': random_pollution(), 'uploaded_files': int(randint(0,11) + (5 * level)), 'appended_files': random_pollution(), 'wb_comments': random_pollution(), 'wb_messages': random_pollution(), 'receiver_comments': random_pollution(), 'receiver_messages': random_pollution() } for k, v in activity_fake.iteritems(): if v < 0: activity_fake[k] = 0 newstat.start = when newstat.summary = activity_fake counter += 1 source_store.add(newstat) print "Committing %d stats" % counter source_store.commit()
def random_login_delay(): """ in case of failed_login_attempts introduces an exponential increasing delay between 0 and 42 seconds the function implements the following table: ---------------------------------- | failed_attempts | delay | | x < 5 | 0 | | 5 | random(5, 25) | | 6 | random(6, 36) | | 7 | random(7, 42) | | 8 <= x <= 42 | random(x, 42) | | x > 42 | 42 | ---------------------------------- """ failed_attempts = GLSettings.failed_login_attempts if failed_attempts >= 5: n = failed_attempts * failed_attempts min_sleep = failed_attempts if failed_attempts < 42 else 42 max_sleep = n if n < 42 else 42 return utility.randint(min_sleep, max_sleep) return 0
def random_login_delay(): """ in case of failed_login_attempts introduces an exponential increasing delay between 0 and 42 seconds the function implements the following table: ---------------------------------- | failed_attempts | delay | | x < 5 | 0 | | 5 | random(5, 25) | | 6 | random(6, 36) | | 7 | random(7, 42) | | 8 <= x <= 42 | random(x, 42) | | x > 42 | 42 | ---------------------------------- """ failed_attempts = GLSetting.failed_login_attempts if failed_attempts >= 5: min_sleep = failed_attempts if failed_attempts < 42 else 42 n = failed_attempts * failed_attempts if n < 42: max_sleep = n else: max_sleep = 42 return utility.randint(min_sleep, max_sleep) return 0
def rstr(self, alphabet, start_range=None, end_range=None, include='', exclude=''): """Generate a random string containing elements from 'alphabet' By default, rstr() will return a string between 1 and 10 characters. You can specify a second argument to get an exact length of string. If you want a string in a range of lengths, specify the start and end of that range as the second and third arguments. If you want to make certain that particular characters appear in the generated string, specify them as "include". If you want to *prevent* certain characters from appearing, pass them as 'exclude'. """ popul = [char for char in list(alphabet) if char not in list(exclude)] if end_range is None: if start_range is None: start_range, end_range = (1, 10) else: k = start_range if end_range: k = randint(start_range, end_range) result = sample_wr(popul, k) + list(include) random_shuffle(result) return ''.join(result)
def _handle_repeat(self, start_range, end_range, value): result = [] end_range = min((end_range, STAR_PLUS_LIMIT)) times = randint(start_range, end_range) for i in xrange(times): result.append(''.join(self._handle_state(i) for i in value)) return ''.join(result)
def random_pollution(): return int(randint(0,11) + (5 * level))