How to randomise pairs of images

Hello everyone,

I’m starting to build a pairwise comparison task with image. Two image appear in the same time on the screen (one at the left and one at the right).
My problem is : when I’m running the experiment the two image are the same cause in the Excel file there is the same image paired.

I want it to be random and know in my data file which images were presented for each trial.

Is there any manner to make them appear randomly left or right for every test subject?

Thanks for your help,


hi @Milena this might not be the best way to do it, but…

you could write Python code to generate an excel file for each subject as the experiment is starting that randomizes the order of each column.

you could have the master file above live in your experiment directory, then create a per-subject file on the fly when the experiment is run. then in the ‘Conditions’ field, you could have a variable referring to the per-subject file.

What I do in this circumstance is have the columns fixed and shuffle a list of coordinates (or x positions) each trial. Make sure you save the x position of the target

I can’t code because I don’t know how to do that…
But it’s complicate Python code ?


Should I have one column with my images and one column with positions?


Add a code component to your trial routine:

Begin Experiment

locations = [[.3,0],[-,3,0]]

Begin Routine


Then add locations[0] as the position for one image and locations[1] as the position for the other, to be updated each routine.

If your task is to say which food has more calories, then you could put the higher calorie food in aliment1 and then add code in Begin Routine for to calculate the correct answer:

if locations[0][0] > 0:
     Answer = 'right'
     Answer = 'left'

For online use, you’d need to add Answer = ‘’ in Begin Experiment

I have change

locations = [[.3,0],[-,3,0]]
locations = [[.3,0],[-.3,0]]

But I have a problem with this code


I try to put :


But it doesn’t work
When I run my experiment with the code I have this error message :

3.0738 WARNING User requested fullscreen with size [1024 768], but screen is actually [1920, 1080]. Using actual size
Traceback (most recent call last):
File “C:\Users\Milena\Desktop\EXP\”, line 201, in
File “mtrand.pyx”, line 4417, in numpy.random.mtrand.RandomState.shuffle
TypeError: object of type ‘int’ has no len()

I made a mistake in my code (I was typing on a mobile). It should have been


This code is about saving the location of the first column

The first word (in quotes) is the name of the column in the data file
The second word (no quotes) is the variable to be saved. locations[0][0] should just save the x coordinate

If you want to also save the x coordinate of the second location, it should be


I don’t have any more bugs with the code thanks.
But it still shows me the same images. Should I add a collone in my excel file?


At the moment you are seeing the same image on both sides because you have the same image twice in each row of your Excel file.

Would you prefer to
a. Have each image paired with a specific other image, but randomise which one is on the left or
b. Randomly pair images from your image set?

I prefer the b

Based on the Multi-session randomisation demo I wrote this morning, I’d just written a “low code” demo for Random Pairs

Random Pairs code | try it

In this demo there is an outer loop that cycles through all stimuli. However, the trial itself is only presented on odd-numbered iterations of the outer loop (remember that the numbering starts from zero). The even numbered iterations save the stimulus to a variable ready to be used in the next trial.