Randomize stimuli by group so I don't have the same stimulus twice in a row

I have a task in which participants see the same stimulus in different variations. There are 16 stimuli, each with 6 different versions. I would like to avoid that they’ll see the same stimulus (albeit a different version) in a row during the task. Is there some way to accomplish this?

Yes, but maybe you have to switch from Builder view to Coder view, and write a small piece of code for your constraints.

OR

Step1 - You can separately create a python code for 16*6 = 96 stimulus list randomization.
Step2 - Randomly shuffle this list of 96 stimulus
Step3 - Check the condition, if two stimulus are same in a row.
Step4 - If all conditions are satisfied, save it as .csv file.
Step5 - Use this file in your psychopy experiment builder.

Where could I find such a small piece of code for my constraints? Alas, I’m not good with Python (else I definitely wouldn’t need to post here).