1import random
2
3#1.A single element
4random.choice(list)
5
6#2.Multiple elements with replacement
7random.choices(list, k = 4)
8
9#3.Multiple elements without replacement
10random.sample(list, 4)
1import random
2names=['Mark', 'Sam', 'Henry']
3
4#Set any array
5random_array_item=random.choice(names)
6
7#Declare a variable as a random choice
8print(random_array_item)
9
10#Print the random choice
11#Or, if you want to arrange them in any order:
12for j in range(names):
13 print(random.choice(names))
1import random
2
3list = ["Item 1", "Item 2", "Item 3"] # List
4item = random.choice(list) # Chooses from list
5print(item) # Prints choice
6
7# From stackoverflow
8# Tried and tested method
1import random
2list = [20, 30, 40, 50 ,60, 70, 80]
3sampling = random.choices(list, k=4) # Choices with repetition
4sampling = random.sample(list, k=4) # Choices without repetition