python select random from list without replacement code example
Example 1: python random select no replace
import random
aList = [20, 40, 80, 100, 120]
print ("choosing 3 random items from a list using random.sample() function")
sampled_list = random.sample(aList, 3)
print(sampled_list)
Example 2: python choose random sample from list
import random
sequence = [i for i in range(20)]
subset = sample(sequence, 5) #5 is the lenth of the sample
print(subset) # prints 5 random numbers from sequence (without replacement)