Randomizing loops to two monitors

Ahh, OK, you clearly know what you’re doing and it seems that you have solved all the difficult stuff already (of creating the secondary window and knowing how to draw to the correct one).

The randomisation is a little bit easier in Python than in MATLAB. You can construct your list of conditions like this:

c = [0, 1] * 10

Builder imports the shuffle function from the numpy.random module, so you can randomise the order of your list just like this:

shuffle(c)

On each trial, you can just pop off the next element in that list to do whatever you need to do. So I’d suggest doing something like this in the “begin routine” tab of your custom code component:

if your_loop_name.thisN == 0: # only do this on the first trial
    conditions = [0, 1] * 10
    shuffle(conditions)

current_condition = conditions.pop() # NB this shrinks the list by 1
thisExp.addData('condition', current_condition) # record this trial's value in the data file.

Then your conditional stuff either continues in the “begin routine” tab (e.g. if it is a one-off thing like setting the window for a stimulus to apply for the rest of the trial), or in the “every frame” tab (if it does things that require to be dynamically updated on every frame):

if current_condition == 0:
    # do some things, e.g.
    some_stimulus.win = win
    other_stimulus.win = win1
else:
    # do the opposite things, e.g.
    some_stimulus.win = win1
    other_stimulus.win = win

Notice that by popping the latest element from the conditions list at the beginning of each trial, we don’t need to keep track of a list index or impose some sort of loop structure to cycle through the list. You’ll realise you’ve successfully migrated away from MATLAB to a more Pythonic style of programming when you find yourself using indices a lot less.

PS: Good Python style is also to use descriptive variable names rather than concise but non-semantic labels like c. :wink:

PPS: