Avoid 3 consecutive trials with the same condition within random loop

OS Win10
PsychoPy version v3.2.4
**Standard Standalone? y
What are you trying to achieve?: Hi everyone, I have sets of trials that include actual stimuli (Type = Stim) and filler items (Type = Fill), they’re all in the same Conditions file. I have set the loop to random but I would like to avoid having more than 3 trials of the same Type (stimuli vs. fillers) back to back.

What did you try to make it work?:
Nothing yet, I’m sure it should be some custom code but I don’t know the syntax.

By the way, I already have a code component on this routine in order to split my sentences, so not sure if the new code should be separate or can go on the existing code component. Here is the existing one below:


Thanks a lot for your help already!
Ludivine