| Reference | Downloads | Github

Randomizing... with exceptions

Hi Brain Trust,

I have three lists of stimuli (e.g. faces, words, and arrows). I have an outer loop that selects a particular combination (order matters here, so word_face or face_word) so six different possible combinations. These combinations lead to two inner loops that both randomly pick one stimulus from each category. This means the outer loop is balanced for combination type, but the inner loops only select one stimulus and it goes back to the outer loop. Thus, there is a small but possible chance that the previous trial could have one of the same stimuli as the next trial. How do I write in an exception (i.e. if last trial had “pic32”, then try another random pic)? I just don’t want consecutive trials to have the same stimulus, but since the inner loops pick one of 88 stimuli and then it goes back to the outer loop to re-randomize the combination, the chances of overlap between consecutive trials are non-zero.

Thanks for any advice,

One simple way to deal with this would be to have a dummy trial in between the main loops.

Alternatively, you could add code that skips the first trial if it matches the last one from the previous loop but then save that trial information to an array so that it can be reinserted in an extra routine after the loop finishes.