import randomgroup_of_items = {'a', 'b', 'c', 'd', 'e'} # a sequence or set will work here.num_to_select = 2 # set the number to select here.list_of_random_items = random.sample(group_of_items, num_to_select)first_random_item = list_of_random_items[0]second_random_item = list_of_random_items[1]
import secrets # imports secure module.secure_random = secrets.SystemRandom() # creates a secure random object.group_of_items = {'a', 'b', 'c', 'd', 'e'} # a sequence or set will work here.num_to_select = 2 # set the number to select here.list_of_random_items = secure_random.sample(group_of_items, num_to_select)first_random_item = list_of_random_items[0]second_random_item = list_of_random_items[1]
import randomlst = ['a', 'b', 'c', 'd', 'e']random.seed(0) # remove this line, if you want different results for each runrand_lst = random.sample(lst,3) # 3 is the number of sample you want to retrieveprint(rand_lst)
Output:['d', 'e', 'a']