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
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
1import random
2sequence = [i for i in range(20)]
3subset = random.sample(sequence, 5) #5 is the lenth of the sample
4print(subset) # prints 5 random numbers from sequence (without replacement)
1import random
2sequence = [i for i in range(20)]
3subset = sample(sequence, 5) #5 is the lenth of the sample
4print(subset) # prints 5 random numbers from sequence (without replacement)