Python Forum

Full Version: So I'm using this bot
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So, I'm using this bot which makes accounts (Some people might know what it's for), and this is the part of the script that I need to edit.

def get_random_name():
    return "{}{}{}".format(fake.first_name(), fake.last_name(), random.randint(200, 900) + random.randint(55, 4444444) )
Meaning it makes a name consisting of a first name, last name, and numbers. And those first and last names are taken from a list of names. I was wondering if there's any way to edit what names will be as first and last, I know I can edit the "{}{}{}" to make the first name always be a specific name, but I'd like for it to be chosen from a list i've made myself. If anybody could help me with this issue I'd appreciate it.
(Sep-03-2017, 04:39 PM)Walrus_Emperor Wrote: [ -> ]Meaning it makes a name consisting of a first name, last name, and numbers. And those first and last names are taken from a list of names.

From what I understand from your question is that you already have a list of the first and last name and you want to randomly choose from it.For that you can use random.choice() to select randomly.

eg-
>>> f = ['a','b','c','d']
>>> l = ['w','x','y','z']
>>> first = random.choice(f)
>>> last = random.choice(l)
>>> print('f: {} l: {}'.format(first,last))
f: c l: w
(Sep-03-2017, 04:52 PM)hbknjr Wrote: [ -> ]
(Sep-03-2017, 04:39 PM)Walrus_Emperor Wrote: [ -> ]Meaning it makes a name consisting of a first name, last name, and numbers. And those first and last names are taken from a list of names.

From what I understand from your question is that you already have a list of the first and last name and you want to randomly choose from it.For that you can use random.choice() to select randomly.

eg-
>>> f = ['a','b','c','d']
>>> l = ['w','x','y','z']
>>> first = random.choice(f)
>>> last = random.choice(l)
>>> print('f: {} l: {}'.format(first,last))
f: c l: w

Alright, so I changed it to
 f = ['test', 'test2']
d = ['test3', 'test4']
	
def get_random_name():
    return "{}{}{}".format(random.choice(f), random.choice(d), random.randint(200, 900) + random.randint(55, 4444444) )
and it works fine, thanks for the help.