In this post we will be creating a script that will select multiple random items from a list, to do this we will be using the random module. The script will take input in the form of an integer which will define the number of random items to return.
See the snippet of code below where we have our list containing ten items.
import random List=['Johnny','Jen','Joe','Jeff','James','Amy','Matt','Monica','Tom','Jil'] Number = int(input("Enter number of random items to select: ")) random_Choices = random.sample(List, Number) print(random_Choices)
When passing this script a value of ‘2’, the following is returned as output.