How to put a list in random order?¶
from random import shuffle
data = ['A','B','C','D']
shuffle(data)
print(data)
How to pick a random sample?¶
import random
# random set with repeats
ALPHABET = list('AGCT')
dna = [random.choice(ALPHABET) for i in range(50)]
print(''.join(dna))
# random set without repeats
NUMBERS = range(1, 101)
print(random.sample(NUMBERS, 10))