Randomization across blocks with special selection

OS : mac sierra 10.12.1
PsychoPy version (e.g. 1.84.x): 1.93
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I am doing an experiment that shows pictures in two conditions (A orB) over two blocks. While in the first block I want 15A + 15B to be randomly selected from 60A +60B, the second block will have to randomly select another 15A +15B from the rest (i.e. the remaining 45A + 45B). However, let’s name each picture in number. For picture no.1, it has an A condition and a B condition (both are generated from pic no.1.) In each block, there should not be A or B generated from the same pic. Therefore, after two blocks, all the pictures should be presented (60 in total) in either A or B condition but not both.

Insert a code component. In the “begin experiment” tab, adapt something like this to your needs:

filenames = [] #to store two sub-lists of files for each block

# single list from 1:60 ensures sampling without replacement:
numbers = list(range(1, 61))
shuffle(numbers) # randomise it

for block in range(2):
    filenames.append([]) # a separate sub-list for each block
    letters = ['A', 'B'] * 15 # balanced list regenerated each block
    shuffle(letters) # randomised
    for trial in range(30):
        trial_number = str(numbers.pop())
        trial_letter = letters.pop()
        filenames[block].append(trial_number + '_' + trial_letter + '.jpg')

I guess you have two loops, an inner one for trials, and an outer one for blocks. In the “begin routine” tab, put something like this:

trial_filename = conditions[your_outer_loop_name.thisN].pop()
thisExp.addData('image', trial_filename) # record it in the data file

You can use the variable trial_filename as required, e.g. put $trial_filename in the image field of your image stimulus component.