Selecting a random row from conditions that changes at each iteration

Hi! I have a condition file with 825 conditions, specifying 825 different stimuli. I need to present just 1 random stimulus per iteration of the loop. However, on every iteration, the randomly selected stimulus must be different. I tried to program that by adding this bit of code in the “selected rows” part of the loop [$np.random.choice( 825 , size = 1 , replace = False)]. With this line, the program does select just one random line out of the condition file. Nevertheless, it continues to select the same line on every iteration of the loop, whereas I want a different random stimulus on each iteration. How can I do that?

thanks!

Why aren’t you using the whole loop with loop type = random? If it’s because you want to end the loop before 825 trials then you can use something like

if trials.thisN == 99: # counting starts at 0 so this would be 100 trials
     trials.finished = True # end the loop at the end of this iteration

This example assumes that your loop is called trials

Hey, thanks for your answer!

I am not using the whole loop with loop type = random because in that case, it goes (randomly, yes) through all of the 825 stimuli. Instead, what I need, is for the loop to go around say only 30 times, and in each of these 30 iterations, I want to show just 1 (randomly selected) stimulus among the 825 stimuli available.

For what concerns the code you wrote, would I put that in a specific code component or can I implement it in the selected rows of the loop builder? Sorry if this is a stupid question, it’s my first experience with PsychoPy.

My code goes in a code component in one of the routines, e.g. the Begin Routine tab in the trial routine

Try replacing 99 with 5 when testing.

oh, nevermind, I got confused… I used your code and it works!

Thanks a lot! It works :slight_smile: