Customizing randomization

OS: Win10
PsychoPy version: 2025.2.4
Do you want it to also run online? (y/n) no
What are you trying to achieve?:

Randomise my set of stimuli (from the uploaded table) so that two consecutive stimuli don’t appear one after another.

Hi everyone. I have a set of stimuli (4 different tables for each experimental list) which includes the first syllable of a word. There’re also two words for each syllable (e.g. BE - belong, BE - behold), 10 words, 5 syllables in total. I want the syllables to be presented in a random order but so the same syllable doesn’t appear twice in a row (e.g. if I see BE, then the next syllable should be any other from my set but BE).

What did you try to make it work?: I read through topics and discussions here for a code that could make it work, but I didn’t manage to find any. But I’m new at psychopy and code component, so maybe I just got it wrong.. I’d be very grateful if someone could help, thanks!

Have a look at my online demos Complex Randomisation and Randomisation without repetition. These are both based on the assumption that you want to control the total number of presentations of each syllable. When I want random without repetition for something I don’t mind being unequal I use the following code:

thisIndex = (thisIndex + 1 + randint(numberOfOptions - 1)) % numberOfOptions

For example, if there are 5 colours in an emotional Stroop task [‘red’, ‘blue’, ‘green’, ‘yellow’, ‘purple’] and the previous value of thisIndex was 2 (“green”) because counting starts from 0 for lists) then randint will generate a random integer from 0 to 3 and the new value of thisIndex will be between 3 (2 + 1 + 0 = 3; 3 % 5 = 3; ‘yellow’) and 6 (2 + 1 + 3 = 6; 6 % 5 = 1; ‘blue’).

1 Like

OMG, thank you SO much, it worked!!

1 Like