How to pseudorandomise text stimuli in Builder?

OS : Mac OS 10.15 Catalina
PsychoPy version : PsychoPy v2020.1.0
**Standard Standalone? (y)

What are you trying to achieve?: I am building the control part of my experiment.
The task is: The word “TARGET” is shown on the screen for 10 seconds and it randomly switches to “target” for 500 ms during that time. The participant should count how many times the word “target” was shown in lower case.

I want to show the lower case word “target” for 500ms, multiple times and randomly during a 10 seconds trial.

What did you try to make it work?: I added a text component with 0.5 sec. duration to my trial. I created an excel sheet with 20 text conditions. (10 times “target”, 10 times “TARGET” ) In that way, I could complete the total duration of the trial to 10 seconds. I set a loop around the trial, loaded my conditions file and chose random as loopType.

What specifically went wrong when you tried that?:
The words are shown randomly but sometimes the lower case “target” is shown consecutively so it lasts more than 500ms.
For example: TARGET - target - target - target -TARGET - TARGET - target …

I was wondering if I could build this task in a more elegant way in Builder, so I prevent this long periods. I could not find how to pseudorandomise the selected conditions in Builder. Unfortunately I am not good with coding yet.

I appreciate any opinion. Thank you for your help! :slight_smile:

Hi Ozge, I’ve only been working with Psychopy for about a month, but had a very similar problem to solve. Looking around Discourse, this is potentially possible with a code component in Builder, but largely depends on what constraints you have.

First thing to note is that you have equal #s of each stim, but one of the stim “target” can never be followed by itself. If you have an equal # of each, the only possible solution is alternating-- if TARGET is followed by itself even once, you’ll always be stuck with at least “target” followed by “target” at the end.

Some limits (particularly specific numbers of each stim) can make it difficult to reach a viable order in a reasonable time, rather than only stim order constraints. Do you have an min/max number of total lowercase "target"s to be presented?

If not (or even if so, but might be reasonable to do this way), you can try the “brute force” method of attempting a psuedorandomized stimuli order at the start of the experiment (& re-pseudorandomize orders until a solution is reached), you could try adapting this post Force trial order reshuffle until a constraint is met to your needs.

If you don’t have limit on eg. # of “target”, you can also create a much larger stim file to pull from that has many more entries of both TARGET and target (eg. 50 of each), and then using the brute force method, cap your list once you hit a viable order that has 20 entries. There’s also ways to limit the time of a loop using a code component.

For my case, I realized that some of the permutations I was trying to run were actually impossible (infinitely looking for a solution!), and after relaxing constraints a little, it still took >10sec to reach a solution, so it didn’t make sense to run that live in the experiment. I ended up generating pseudorandom orders offline and randomly assigning them to participants.

Good luck!