I am very new to Python and I have run into a problem that I can’t find the solution for. I am trying to create a unique character generator, to create the names I have a pool of names that are in a .txt file and also suffix’ which are in another one. However, I run into the problem that when I run the code sometimes the same names appear as they are chosen at random each time round. This is the code that I have written for it:
import random a_file = open("Alien_Names.txt", "r") a_names = [(line.strip()).split() for line in a_file] a_file.close() b_file = open("suffix.txt", "r") b_names = [(line.strip()).split() for line in b_file] b_file.close() def repeat(): fname = random.choice(a_names) sname = random.choice(b_names) print(fname, sname) for i in range (10): repeat()
I will be thankful for any help.