Randomize a trial under the condition that only one of three types of image stimulus cannot appear consecutively

PsychoPy version (v2023.2.3)

Hello all, I’m new starting to use psychopy and I have some problems with an experiment.

For some background, what I’m trying to do is to make an experiment that is going to show in the scream different images (one by one and randomly), of three types of images/stimuli (positives, negatives, and neutral). And the participants have to press “space” when a specific type of image appears. All the images are in an excel sheet of three columns that show the name of the image (their path for the program to find them), their type, and which of them are the correct ones (the ones that we want the participant to press “space”).

What I need help with is that the images displayed on the screen have to be radomized under the condition that only one type of image (of the three types possible) can’t display consecutive. Considering that each type of stimuli could have different images associated that are mapped in the excel. Also, I want to point that the images that I want to appear under this condition are the ones that want to pass when the participant press “space”.

Any information on how to fix this or what I should do would be greatly appreciated ^^