import random
A = [0,7,8,15,16,23,24,31]
B = [1,2,3,4,5,6,25,26,27,28,29,30,9,14,17,22]
C = [10,11,12,13,14, 18,19,20,21]
def sample_k(k):
ret = []
counter = 0
for _ in range(k):
while True:
# select a group
v = random.random()
if v < .5:
g = A
elif v < .95:
g = B
else:
g = C
# select a num
v = random.choice(g)
counter += 1
if v not in ret[-6:]:
ret.append(v)
break
return ret, counter
seq, count = sample_k(100)
print(seq)
print(count)
Standard input is empty
[0, 29, 5, 23, 14, 31, 22, 7, 3, 16, 6, 4, 27, 24, 22, 0, 7, 5, 17, 15, 1, 29, 19, 16, 27, 8, 24, 25, 9, 23, 3, 16, 17, 28, 8, 0, 31, 23, 29, 10, 25, 16, 5, 9, 24, 31, 17, 27, 8, 4, 10, 25, 0, 31, 24, 30, 22, 15, 8, 29, 18, 0, 16, 9, 25, 26, 14, 31, 30, 4, 22, 16, 17, 29, 24, 8, 23, 1, 31, 0, 6, 5, 24, 4, 14, 19, 17, 29, 16, 30, 0, 24, 22, 23, 17, 31, 26, 1, 25, 16] 129