You can download this code by clicking the button below.
This code is now available for download.
This function uses the Faker library to generate a dictionary containing a user's name, address, email, and phone number. Depending on the parameters passed, it can optionally generate only the name or address.
Technology Stack : Faker
Code Type : Function
Code Difficulty : Intermediate
def generate_random_user(arg1, arg2):
import random
from faker import Faker
fake = Faker()
user = {
'name': fake.name(),
'address': fake.address(),
'email': fake.email(),
'phone_number': fake.phone_number()
}
if arg1:
user['name'] = fake.name()
if arg2:
user['address'] = fake.address()
return user