lundi 16 mars 2015

Limit the number of repeats in pseudo random python list

For a science experiment, I need to generate a pseudo-random order for administering two different tests, 10 times each. I've used this code:



import random
randy = [1] * 10 + [2] * 10
random.shuffle(randy)


This gives me a nicely shuffled order for testing, however I need to ensure that the max number of repeated tests is not larger than 3. In other words, don't administer the "1" test more than 3 times in a row.


Can anyone think of a good way to do this? Shuffling multiple times does not guarantee success. Any way I can robustly check the shuffled list and change it accordingly? Thanks!


Aucun commentaire:

Enregistrer un commentaire