vendredi 3 avril 2020

Returning of random values

I've created random person generator. Divided into functions and class that define the person. I'm using a Json file for the names. But when I run the code, the name of the person, and the email are diffrent random names, although they are on the same function. I'm guessing it as something to do with wrong return of the function.

def Person():
    files = ['global', 'local']
    file = choice(files)
    with open('names/{}.json'.format(file)) as f:
        data = json.load(f)
    randomFirst = randint(0, (len(data['first']) - 1))
    randomLast = randint(0, (len(data['last']) - 1))
    firstName = data['first'][randomFirst]
    lastName = data['last'][randomLast]
    email = firstName.lower() + '.' + lastName.lower() + str(suffix) + choice(domain)

    return firstName, lastName, email

user = User(Person()[0], Person()[1], Person()[2])

Output:

Name:Sarah Gagnon, Email:sofia.sanchez200@yandex.com



Aucun commentaire:

Enregistrer un commentaire