Display randomly two categories of images


I’ve been reading through a lot of past posts, but there’s one issue that I haven’t been able to deal with. What I’m trying to build is an experiment where I want to randomly display two categories of images: stressful ones and relaxing ones. More specifically, I would like to display to participants 3 images for 6 seconds with 1 second blank between each one and a period of 20 seconds at the end of the trial. So the paradigm would be like this :
1S + blank + 1S + blank + 1S + rest (x5)
1NS + blank + 1NS + blank + 1NS + rest (x5)
(S : stressful; NS : no stressful)

I have managed to randomly display stressful or no stressful pictures by creating two lists of images but the issue is that I always have stressful pictures first (repeated 5 times) then no stressful images (repeated 5 times).
So, I would like to build 5 blocs with 10 trials (5 stressful and 5 non-stressful; pseudo-randomized). I don’t know if this is possible, but I would like to create a single list of images (stressful and no-stressful) and add a condition where if the first picture selected is stressful, then the two followings have to be stressful as well. Same goes with no-stressful pictures.

Does anyone have any advice ?
Thanks in advance for your time and assistance !

Best regards,

If you want to present 3 images within a single routine (or at least a single iteration of your trials loop) then I would recommend preloading the pictures into two lists in a setup loop and then pop images from the relevant list when needed.

Begin Experiment

stressful = []
nonstressful = []

Begin Routine (setup loop)

stressful.append(Stressful) # Stressful being image column in spreadsheet
nonstressful.append(Nonstressful) # Nonstressful being image column in spreadsheet

Begin Routine (gap between setup and trials)


Begin Routine (trials loop)

if condition == 'stressful':
     image1 = stressful.pop()
     image2 = stressful.pop()
     image3 = stressful.pop()
     image1 = nonstressful.pop()
     image2 = nonstressful.pop()
     image3 = nonstressful.pop()


Thank you, that’s exactly what I was looking for !