Randomization coding

For my stimuli I have to possible answers: A or B. I’ve set the stimuli to random but would like to ensure that there will never be 3 in a row of A or three in a row of B. I have no coding experience so details would be greatly appreciated.

Thanks in advance,
Mary

What you’ll need to do is store your stimulus’s previous values. If you add a Variable component at the start of the experiment setting the value of a variable to be an empty list [], then you can use a Code component to store the stimulus’s value at the end of each trial. So in the End Routine tab have something like:

stimValStore.append(VALUE)

Then, in the Begin Routine tab, add:

if stimValStore[-2] == stimValStore[-1] == VALUE == 'A':
   VALUE = 'B'
elif stimValStore[-2] == stimValStore[-1] == VALUE == 'B':
    VALUE = 'A'

(with VALUE replaced by whatever your stimulus value is)

So essentially “If the value is A, the last value was A and the value before was A, make this value B (and vice versa)”