How to pseudorandomise text stimuli in Builder?

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!