| Reference | Downloads | Github

Selection of set number of random trials

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 3.2.4
Standard Standalone? (y/n) y
What are you trying to achieve?:

Hi everyone,

I’m quite new to psychopy (and programming - that’s why I’m going with the builder mode) and would appreciate your help. In general, my experiment is a sentence/picture matching task (i.e. each trial consists of a sound file + image file) preceeded by a priming condition (a sound file).

So my experiment should go like this:

block of 6 trials
block of 6 trials

I have 48 trials, 6 of which I’d like to be randomly chosen once (i.e. not repeated) for each block, until all trials are done.

In case there isn’t a problem so far, let me add one: the prime has 2 levels (i.e. 2 sound files) which need to be counter balanced.

Imaginary solution 1:
create two experiments that have pre-loaded the counterbalanced primes
figure out a way to randomly select 6 trials for each block
loop to prime1

(and the counterbalanced version with prime2 first)

Imaginary solution 2:
create one experiment that starts randomly with either one prime and then an If conditional within the loop to present the other prime the next time
loop(with the other prime)

I’m sure that each of the solutions might have a different way of selecting a set number of random trials from my variables file, so I’m sorry for the long post!

What did you try to make it work?:

I’ve more or less done the solution 1, but the problem is that I don’t know how to get a random selection out of the 48 items from the variables file. For the block 1 I have a selection of 0:6

and for the block 2 I have a selection of 6:12

But it randomly selects out of this range and I obviously need it to select randomly 6 out of the 48.

When it has shown all 48 trials, I’ll need to end the loop and get a message that the experiment is over.

Also, if you have a suggestion of how I could optimise this (i.e. imaginary solution 2) I’d greatly appreciate it!


This could indeed be done 2 ways. I think the easiest is not really to treat it as blocks but as a continuous set of trials where you insert a pause occasionally that makes it look to the participant like ‘blocks’ which you could do with the following files:
conditions.xlsx (8.3 KB) fakeBlocks.psyexp (15.8 KB)


In that I handled the counterbalanced prime by creating a list of 48 primes (equal numbers), shuffling that list and then fetching the next one on each trial

The other option where you use a loop for trials and then another for blocks is a bit trickier but possible. For that you’d have to create a list of indices into the conditions file and pass that list in each time. It’s possible but there’s more to keep track of that way.