xxxxxxxxxx
import random
sequence = [i for i in range(20)]
subset = random.sample(sequence, 5) #5 is the lenth of the sample
print(subset) # prints 5 random numbers from sequence (without replacement)
xxxxxxxxxx
import random
#1.A single element
random.choice(list)
#2.Multiple elements with replacement
random.choices(list, k = 4)
#3.Multiple elements without replacement
random.sample(list, 4)
xxxxxxxxxx
import random
list = [20, 30, 40, 50 ,60, 70, 80]
sampling = random.choices(list, k=4) # Choices with repetition
sampling = random.sample(list, k=4) # Choices without repetition
xxxxxxxxxx
import random
choose = ["Egg","Rat","Rabbit","Frog","Human"]
Choosen = random.choice(choose)
print(Choosen)
xxxxxxxxxx
#import the random module
import random
my_list = ['apple', 'banana', 'orange', 'strawberry', 'mango']
#pick a random item from the list
print(random.choice(my_list))
xxxxxxxxxx
import random
numberList = [1,2,3,4,5]
print(random.choice(numberList)) # Prints a random number from the list
xxxxxxxxxx
import random
my_list = [1, 2, 3, 4, 5]
random_element = random.choice(my_list)
print(random_element)
xxxxxxxxxx
import random
my_list = [1, 2, 3, 4, 5]
random_element = random.choice(my_list)
print(random_element)
xxxxxxxxxx
#import the random module
import random
my_list = ['apple', 'banana', 'orange', 'strawberry', 'mango']
#pick a random item from the list
print(random.choice(my_list))