| Reference | Downloads | Github

Choose a single random stimulus from condition file and end routine

Hello all,

I have a conditions file in a routine which has 4 stimuli inside it, all I want is that a single stimulus (probe A) will be chosen from this file and presented to the participant, then we will have another routine (probe B) where again we will choose a stimulus from this conditions file however it mustn’t be the same as the one presented in probe A. I can do this part by saving the stimulus presented to a variable and comparing , no problem. But I cant be sure how I can interfere with the loop so that this matching stimulus wouldn’t be presented and instead another random stimuli would be chosen. Maybe continue the loop?

I know Python well, so I looked around the documentation and pschopy library, I couldn’t find a method to provide a list of the stimuli. Is there such method?

There is a trialList (and Im not sure how this works) however this works when you make a loop. When I make a loop all of these stimuli gets presented once (since I have a n=1 loop) so a total of 4 images are presented. I want to present the one stimulus, just once.

I thought of hard-coding the list of stimuli to an array but I think keeping the conditions file would be neater, so I wouldn’t need to code to add new stimuli in the future.


Hi @Tamer_Gezici,

How complex is the rest of your conditions file? You could try, rather than having a column with all the stimuli in, having a column for each and then choosing a column at random. For example:

import random
colChoice = random.choice([

and then setting the stimulus to be $colChoice. Would that work?

Thank you for reply. I thought of that too, and frankly my conditions file is quite simple so this would work.

However, I noticed that what I can do is create a random splice like this:

splice_A = randint(0,stimulus_num-1)
random_spliceA = str(splice_A) + ':' + str(splice_A+1)

Then to the loop I just placed the selected rows field with the variable as $random_spliceA. This selects a single random stimulus from the conditions list. shuffle method can be used to randomize the order of the stimulus for multiple stimuli, I guess.

For future reference: Stimulus num must be your number of stimulus and if you wish to select more rows you can change the number deducted and the number which is added which is 1 at this case, as the upper limit.

1 Like