Randomise stimuli without consecutive presentation


I am programming a psychological experiment.
In every trial, they read a scenario and see a face photo and hear an answer for the scenario.

Scenarios are 20.
And there are 4 conditions for the scenarios. (Happy face-Happy sound, Neutral face-Happy sound, Happy face-Neutral sound, Neutral face-Neutral sound)

Therefore, All trials are 80. (Scenario 20 * Condition 4)

The point is I need to randomize scenario order without repeating stimuli twice in a row.
My problem is that the “random trials” must NOT include consecutive presentations of one scenario.
For example, scenario 1(Happy f-Happy v) → scenario 1(Happy f-Neural v)
Or scenario 1 - 3 - 5 - 6 - 7- 8 - 3 - 4 - 4- 5 - 10

However, I am very new to psychopy/coding and am not sure of how to do this.
Is anyone able to please help guide me in generating a code that will constrain the randomisation process so that no one square/keys be presented consecutively?


Hello you330,

you need some code to do this.

These should give you the relevant information.

Best wishes Jens

Here’s a new method I’ve just written and added to my Online Demos.

Randomisation without repetition code | try it

This demo presents a new method of randomising a set of trial types without consecutive presentation of the same type. Instead of loading the trials into a list and then shuffling until a suitable order has been created, it skips consecutive presentations and then repeats the loop only selecting those trials. Since there is a danger that doing this on the fly can end up with an insoluble problem (for example, the final two trials are of the same trial type), this method will add an extra trial into the new list. The participant may therefore end up seeing one or two additional trials in the experiment, but they can easily be excluded from the analysis if desired, using column that records the presentation number.