Random selection from a list - is there a better way? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Random selection from a list - is there a better way?

Very new to Python and interested in writing a random name generator my current project. This was what first came to mind. Is there a more efficient way to achieve the same results? I feel like I might be missing something simple... names = ["Tom", "Harry", "Melissa", "Andrew", "Stacy", "Jack"] name_choice = random.randint(0, (len(names)-1)) print(names[name_choice])

15th May 2017, 4:47 AM
Homer P
Homer P - avatar
1 Answer
0
Exactly what I was after. Thank you!
15th May 2017, 5:29 AM
Homer P
Homer P - avatar