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