python randomly generated test data

python randomly generated test data

 

 

"" " Some methods generator generates a random number, phone number, and the like consecutive numbers " "" 
Import Random
 from faker Import Faker

fake = Faker('zh_cn')


DEF random_phone_number ():
     "" " random phone number " "" 
    return fake.phone_number ()


DEF random_country ():
     '' ' random States ' '' 
    return fake.country ()


DEF random_city ():
     '' ' random city ' '' 
    return fake.city ()


def random_city_suffix():
    '''随机县'''
    return fake.city_suffix()


def random_address():
    """随机地址"""
    return fake.address()


def random_street_address():
    '''街道'''
    return fake.street_address()


def random_street_name():
    '''街道名'''
    return fake.street_name()


def random_postcode():
    '''邮编'''
    return fake.postcode()


def random_latitude():
    '''维度'''
    return fake.latitude()


def random_longitude():
    '''经度'''
    return fake.longitude()


DEF random_name ():
     "" " randomly name " "" 
    return fake.name ()


def random_last_name():
    ''''''
    return fake.last_name()


def random_first_name():
    ''''''
    return fake.first_name()


def random_name_male():
    '''男性姓名'''
    return fake.name_male()


def random_last_name_male():
    '''男性姓'''
    return fake.last_name_male()


def random_first_name_male():
    '''男性名'''
    return fake.first_name_male()


def random_name_female():
    '''女性姓名'''
    return fake.name_female()


DEF random_ean8 ():
     '' ' . 8 bit barcode ' '' 
    return fake.ean8 ()


DEF random_ean13 ():
     '' ' 13 is bit barcode ' '' 
    return fake.ean13 ()


DEF random_ean ():
     '' ' custom-digit bar code, can only be selected from 8 or 13 is ' '' 
    return fake.ean (length = 8 )


DEF random_company ():
     '' ' company name ' '' 
    return fake.company ()


DEF random_company_suffix ():
     '' ' company name suffix ' '' 
    return fake.company_suffix ()


def random_credit_card_number():
    '''卡号'''
    return fake.credit_card_number(card_type=None)


DEF random_credit_card_provider ():
     '' ' card provider ' '' 
    return fake.credit_card_provider (CARD_TYPE = None)


DEF random_credit_card_security_code ():
     '' ' secure password card ' '' 
    return fake.credit_card_security_code (CARD_TYPE = None)


DEF random_credit_card_expire ():
     '' ' Card Validity ' '' 
    return fake.credit_card_expire ()


DEF random_credit_card_full ():
     '' ' complete card information ' '' 
    return fake.credit_card_full (CARD_TYPE = None)


def random_currency_code():
    '''货币代码'''
    return fake.currency_code()


DEF random_date_time ():
     '' ' random date and time ' '' 
    return fake.date_time (tzinfo = None)


DEF random_iso8601 ():
     '' ' dates to the standard output iso8601 ' '' 
    return fake.iso8601 (tzinfo = None)


def random_date_time_this_month():
    '''本月的某个日期'''
    return fake.date_time_this_month(before_now=True, after_now=False, tzinfo=None)


def random_date_time_this_year():
    '''本年的某个日期'''
    return fake.date_time_this_year(before_now=True, after_now=False, tzinfo=None)


def random_date_time_this_decade():
    '''本年代内的一个日期'''
    return fake.date_time_this_decade(before_now=True, after_now=False, tzinfo=None)


def random_date_time_this_century():
    '''本世纪一个日期'''
    return fake.date_time_this_century(before_now=True, after_now=False, tzinfo=None)


DEF random_date_time_between ():
     '' ' a random time between two time ' '' 
    return fake.date_time_between (START_DATE = " -30y " , END_DATE = " now " , tzinfo = None)


def random_timezone():
    '''时区'''
    return fake.timezone()


DEF random_time ():
     '' ' Time (customizable format) ' '' 
    return fake.time (pattern = " % H:% M:% S " )


DEF random_am_pm ():
     '' ' random Morning Afternoon ' '' 
    return fake.am_pm ()


DEF random_month ():
     '' ' random month ' '' 
    return fake.month ()


DEF random_month_name ():
     '' ' Random month name ' '' 
    return fake.month_name ()


DEF random_year ():
     '' ' Randomized ' '' 
    return fake.year ()


DEF random_day_of_week ():
     '' ' random week ' '' 
    return fake.day_of_week ()


DEF random_day_of_month ():
     '' ' random day of month ' '' 
    return fake.day_of_month ()


DEF random_time_delta ():
     '' ' random time delay ' '' 
    return fake.time_delta ()


DEF random_date_object ():
     '' ' random target date ' '' 
    return fake.date_object ()


DEF random_time_object ():
     '' ' random time objects ' '' 
    return fake.time_object ()


DEF random_unix_time ():
     '' ' random unix time (time stamp ' '' 
    return fake.unix_time ()


DEF random_date ():
     '' ' random date (customizable format ' '' 
    return fake.date (pattern = " % Y-M-% D% " )


DEF random_date_time_ad ():
     '' ' AD random date ' '' 
    return fake.date_time_ad (tzinfo = None)


DEF random_job ():
     '' ' job ' '' 
    return fake.job ()


DEF random_text ():
     '' ' randomly generate an article ' '' 
    return fake.text (= 200 is max_nb_chars )


DEF random_word ():
     '' ' random words ' '' 
    return fake.word ()


DEF random_words ():
     '' ' randomly generate words ' '' 
    return fake.words (= Nb. 3 )


DEF random_sentence ():
     '' ' randomly generate a sentence ' '' 
    return fake.sentence (nb_words =. 6, variable_nb_words = True)


DEF random_sentences ():
     '' ' randomly generate several sentences ' '' 
    return fake.sentences (= Nb. 3 )


DEF random_paragraph ():
     '' ' randomly generate a text (character string) ' '' 
    return fake.paragraph (= nb_sentences. 3, variable_nb_sentences = True)


DEF random_paragraphs ():
     '' ' randomly generated text into paragraphs (list) ' '' 
    return fake.paragraphs (= Nb. 3 )


DEF random_password ():
     '' ' random password (password policy can be specified) ' '' 
    return fake.password (length = 10, special_chars = True, digits = True, UPPER_CASE = True, lower_case, = True)


def random_uuid4():
    '''随机uuid'''
    return fake.uuid4()


DEF random_locale ():
     '' ' randomized native code ' '' 
    return fake.locale ()


DEF random_phonenumber_prefix ():
     '' ' operating business segment, the top three mobile phone number ' '' 
    return fake.phonenumber_prefix ()


def random_pyint():
    '''随机int'''
    return fake.pyint()


DEF random_pystr ():
     '' ' random string (length specification) ' '' 
    return fake.pystr (min_chars = None, 20 is MAX_CHARS = )


def random_user_agent():
    '''伪造UA'''
    return fake.user_agent()


def random_num(length):
    """随机数字"""
    return fake.random_number(length)


def random_email():
    """随机email"""
    return fake.email()


DEF random_ipv4 ():
     "" " randomly IPV4 address " "" 
    return fake.ipv4 ()


DEF random_str (min_chars = 0, = MAX_CHARS. 8 ):
     "" " length of the random string between the maximum and minimum " "" 
    return fake.pystr (min_chars = min_chars, MAX_CHARS = MAX_CHARS)


DEF factory_generate_ids (starting_id =. 1, INCREMENT =. 1 ):
     "" " . returns a generator function, calling this function generator generates, from the beginning starting_id steps of INCREMENT " ""

    def generate_started_ids():
        val = starting_id
        local_increment = increment
        while True:
            yield val
            val += local_increment

    return generate_started_ids


DEF factory_choice_generator (values):
     "" " . returns a generator function, calling this function generator generates, randomly selected from a given list of " ""

    def choice_generator():
        my_list = list(values)
        rand = random.Random()
        while True:
            yield random.choice(my_list)

    return choice_generator


if __name__ == '__main__':
    
    print(random_num(8))
    print(random_words())
    print(random_city())
    a=random_phone_number()
    print(a)

 

Guess you like

Origin www.cnblogs.com/y-sh/p/11900923.html