def words(self, nb=3): """ Generate an array of random words :example: array('Надіньте', 'фуражка', 'зелено') :param nb: how many words to return """ return random.sample(self.word_list, nb)
def ssn(cls): #create an array of 8 elements initialized randomly digits = random.sample(range(10), 8) # All of the digits must sum to a multiple of 10. # sum the first 8 and set 9th to the value to get to a multiple of 10 digits.append(10 - (sum(digits) % 10)) #digits is now the digital root of the number we want multiplied by the magic number 121 212 121 #reverse the multiplication which occurred on every other element for i in range(1, len(digits), 2): if digits[i] % 2 == 0: digits[i] = (digits[i] / 2) else: digits[i] = (digits[i] + 9) / 2 #build the resulting SIN string sin = "" for i in range(0, len(digits), 1): sin += str(digits[i]) #add a space to make it conform to normal standards in Canada if i % 3 == 2: sin += " " #finally return our random but valid SIN return sin
def ssn(cls): """ Returns a 9 digits Dutch SSN called "burgerservicenummer (BSN)". the Dutch "burgerservicenummer (BSN)" needs to pass the "11-proef", which is a check digit approach; this function essentially reverses the checksum steps to create a random valid BSN (which is 9 digits). """ # see http://nl.wikipedia.org/wiki/Burgerservicenummer (in Dutch) def _checksum(digits): factors = (9, 8, 7, 6, 5, 4, 3, 2, -1) s = 0 for i in range(len(digits)): s += digits[i] * factors[i] return s while True: # create an array of first 8 elements initialized randomly digits = random.sample(range(10), 8) # sum those 8 digits according to (part of) the "11-proef" s = _checksum(digits) # determine the last digit to make it qualify the test digits.append((s % 11) % 10) # repeat steps until it does qualify the test if (0 == (_checksum(digits) % 11)): break # build the resulting BSN bsn = "".join([str(e) for e in digits]) # finally return our random but valid BSN return bsn
def ide(cls): """ Generates a IDE number (9 digits). http://www.bfs.admin.ch/bfs/portal/fr/index/themen/00/05/blank/03/02.html """ def _checksum(digits): factors = (5, 4, 3, 2, 7, 6, 5, 4) sum = 0 for i in range(len(digits)): sum += digits[i] * factors[i] return sum % 11 while True: # create an array of first 8 elements initialized randomly digits = random.sample(range(10), 8) # sum those 8 digits according to (part of) the "modulo 11" sum = _checksum(digits) # determine the last digit to make it qualify the test control_number = 11 - sum if (control_number != 10): digits.append(control_number) break digits = ''.join([str(digit) for digit in digits]) # finally return our random but valid BSN return 'CHE-' + digits[0:3] + '.'\ + digits[3:6] + '.'\ + digits[6:9]
def ssn(cls): # create an array of 8 elements initialized randomly digits = random.sample(range(10), 8) # All of the digits must sum to a multiple of 10. # sum the first 8 and set 9th to the value to get to a multiple of 10 digits.append(10 - (sum(digits) % 10)) # digits is now the digital root of the number we want multiplied by the magic number 121 212 121 # reverse the multiplication which occurred on every other element for i in range(1, len(digits), 2): if digits[i] % 2 == 0: digits[i] = (digits[i] / 2) else: digits[i] = (digits[i] + 9) / 2 # build the resulting SIN string sin = "" for i in range(0, len(digits), 1): sin += str(digits[i]) # add a space to make it conform to normal standards in Canada if i % 3 == 2: sin += " " # finally return our random but valid SIN return sin
def ssn(cls): digits = random.sample(range(10), 9) dv = checksum(digits) digits.append(dv) digits.append(checksum(digits)) return ''.join(map(str, digits))
def ssn(cls): """ Returns a 13 digits Swiss SSN named AHV (German) or AVS (French and Italian) See: http://www.bsv.admin.ch/themen/ahv/00011/02185/ """ def _checksum(digits): evensum = sum(digits[:-1:2]) oddsum = sum(digits[1::2]) return (10 - ((evensum + oddsum * 3) % 10)) % 10 digits = [7, 5, 6] # create an array of first 9 elements initialized randomly digits += random.sample(range(10), 9) # determine the last digit to make it qualify the test digits.append(_checksum(digits)) # repeat steps until it does qualify the test digits = ''.join([str(d) for d in digits]) ssn = digits[:3] + '.' \ + digits[3:7] + '.' \ + digits[7:11] + '.' \ + digits[11:] return ssn
def rationaleTypes(self, amount=3): return random.sample(self.rationale_types, amount)
def signature(self): os_evn_list = [u'network_http', u'allocates_rwx', u'creates_exe'] return random.sample(os_evn_list, 2)
def domain(self): return '.'.join([ ''.join( random.sample(string.ascii_lowercase, random.randint(4, 10))) for i in range(random.randint(3, 6)) ])
def env(self): os_evn_list = 'flash17.0.0.188,cn,sp1,windows7,agent,java7,office2010,ie11,adobe_reader9.0.0,x86'.split( ',') return ','.join(random.sample(os_evn_list, 2))
def url(self): return 'http://%s ' % '.'.join([ ''.join( random.sample(string.ascii_lowercase, random.randint(4, 10))) for i in range(random.randint(3, 6)) ])
faker_tags= [Tag(name=faker.word()) for i in range(20)] session.add_all(faker_tags) faker_article=[] for i in range(100): article = Article( titile=faker.sentence(), content=' '.join(faker.sentences(nb=random.randint(70, 100))), author=random.choice(faker_users), pubdate = faker.date_time(), type = faker.random_int(min=1,max=6), reading_volume = faker.random_int(min=100,max=900), cost_integral = faker.random_int(min=1,max=10) ) for tag in random.sample(faker_tags, random.randint(2, 5)): article.tags.append(tag) faker_article.append(article) session.add_all(faker_article) credit_category =[[1,"用户登录"],[50,"用户注册"],[2,"评论文章"],[-5,"阅读文章"],[200,"用户投稿"]] faker_credit = [Credit( category=credit_category[random.randint(0,4)][1], credit=credit_category[random.randint(0,4)][0], user=random.choice(faker_users), createtime=faker.date_time(), updatetime=faker.date_time() ) for i in range(10)] session.add_all(faker_users)