You can use the random module.
If you allow duplication, it is convenient to use List compression and choice functions If you do not allow duplication, you can use the sample function.
import random
# Allow duplication
count = 2
sampleList = ['a', 'b', 'c', 'd', 'e']
print [random.choice(sampleList) for i in range(count)]
# Allow Duplicate X
print random.sample(sampleList, count)
© 2024 OneMinuteCode. All rights reserved.