Randomization of a list of images, but manteining the order of the type of image

What are you trying to achieve?:

My experiment has 60 images: 20 neutral, 20 negative and 20 positive. I randomized them in excel and now i have this specific order:

Neu

Neg

Pos

Neg

Neg

Neu

Pos

Neg

Neu

Pos

Neu

Neg

Pos

Neu

Neu

Neg

Pos

Neg

Pos

Neg

Pos

Neu

Neg

Neu

Pos

Neg

Neu

Neg

Neu

Neg

Pos

Neu

Pos

Neg

Pos

Neu

Neg

Pos

Neu

Pos

Neu

Neg

Neu

Pos

Pos

Neg

Neu

Pos

Pos

Neg

Neu

Neg

Pos

Neu

Pos

Neg

Neu

Pos

Neu

Neg

The first image can be any of the 20 neutral images, for example. But the next neutral image can be any of the 19 left, ‘cause i don’t want any repetition.

In sum, i want the images to be selected randomly, but without repetition, and for each specific type. The order of the type must be maintained.

I really don’t know how to do this. I couldn’t find any help by reading other foruns. Please somebody helllpppp…

What I would do is preload the images into three separate shuffled lists and then use .pop() to take an image from the appropriate list on each trial.

Have a look at some of my online demos from PsychoPy Online Demos such as Complex Randomisation (which preloads in code), Independent Randomisation, or Trial Switching

Hi, thank you for answering!

I forgot to mention: I am really new at programming and Psychopy. So i’m having a really hard time understanding what you suggested me to do…

Your suggestion is based on two parts:

  1. Preload the images into three separate shuffled lists;

  2. Use .pop() to take an image from the appropriate list on each trial.

But i don’t know how to preload, and i didn’t find anything about how to use .pop. I’m really lost…

The only thing i tried was a chatgpt suggestion:

import pandas as pd

import random

excel_data = pd.read_excel(“Roteiro_Exp1_v4CAMINHOCOMPLETOONLY.xlsx”) # Replace with the actual Excel file name # Read the Excel file

neutral_images = excel_data[“Caminho_completo_neutro”].tolist() # Extract the columns as lists

negative_images = excel_data[“Caminho_completo_negativo”].tolist()

positive_images = excel_data[“Caminho_completo_positivo”].tolist()

random.shuffle(neutral_images) # Shuffle each list independently

random.shuffle(negative_images)

random.shuffle(positive_images)

shuffled_images = # Combine shuffled lists maintaining the order of types

shuffled_images.extend(neutral_images)

shuffled_images.extend(negative_images)

shuffled_images.extend(positive_images)


But this error appears when i run the experiment:

Alert 4210:JavaScript Syntax Error in ‘Begin JS Experiment’ tab. See ‘Line 1: Unexpected token’ in the ‘Begin JS Experiment’ tab.

For further info see 4210: Probable syntax error detected in your JavaScript code — PsychoPy v2023.2.0


Here’s my excel file with the three columns of conditions and the list of the images:

Roteiro_Exp1_v4CAMINHOCOMPLETOONLY.xlsx (11.3 KB)

And here’s the prinstscreen of my experiment:

Thanks for any help!

Do you want to run this online? If so, then you can’t import pandas.

Have you looked at the code in the demos I mentions, with preload stimuli in two different ways?