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:
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’).
Hi! Is there a way to make this code work if I have more than one routine in one loop both of which have a variable from my table of stimuli?
I tried the code with only one-routine loop and it worked, but my situation is the following: I have three routines in my loop, 1) the one I described in the very first message, it has a text component and it contains a variable from my table (syllable aka first two letters of a word); 2) just a blank screen, it’s a 1-second pause; 3) routine with another text component that contains another variable from my table (first three letters of the same word that was implied in the first routine).
So basically what I did: I inserted a code component (with the thisIndex code you sent me) in the first routine (syllable). It didn’t work, there’s still a chance that I get two consequent syllables that are the same. But if I have only one routine in the loop, then it works the way it should
P.S. If I add any kind of routine, even if I add a blank screen pause, it still stops working.. would be very grateful for your suggestions
Routine 1 uses my code for randomising without repetition.
Routine 3 uses another syllable and you want to avoid repetition between routine 1 and routine 3 and also routine 3 and the routine 1 of the following iteration?
This should be fine if routines 1 and 3 both use the code rather than referring to the spreadsheet.
no. See, routine 3 kinda follows routine 1. So if the syllable that is shown to me during routine one is row number 5 in my sheet, then during routine 3 I will be shown a variable from the same row number 5 (e.g. routine 1 is BA, and routine 3 is BAL). This kind of repetition I need, but psychopy does it automatically somehow. What I don’t want is the repetition of the syllable of Routine 1 in the following iteration. Let’s say I just had BA (R1), then BAC (R3). I have another row in my table that has BA for the R1 but the R3 variable is different, BAL. And so I need to avoid the same two-letter syllable in two consequent iterations.
I tried using your code in routine 3 as well, but since it’s connected to routine 1 in a way I described above, nothing happens, and code stops working in both of the routines.
In that case you need to randomise the rows using the principles in one of my other demos (Complex Randomisation or Randomisation without Repetition) not my code for simple randomisation of stimuli.
Unless – for example, row 5 can work equally well with BA and BE, etc, in which case you just remove the syllable from the spreadsheet.