from random import sample, randint with open("list.txt") as surnames_list: surnames = surnames_list.read().splitlines() surnames = sample(surnames, randint(5, len(surnames))) print(surnames)