Unusual trial structure (sequential-random hybrid)

My experiment is set up such that two images will be shown on each trial. In trials 0-4 (using Python indexing), the participant has to select image A. In trials 5-9, the participant has to select image B. This goes on until the end of the experiment (i.e. if trial number <=4, image A, else image B).

In addition, there are two IVs with 4 and 2 levels each. I want to fully randomize these conditions throughout the experiment and at the same time ensure that these conditions are equally distributed between the two images. I am having trouble getting this to work - any help would be appreciated. I have been coding everything in Javascript/PsychoJS as I am very unfamiliar with Builder. If someone has a solution in JavaScript (pseudocode is fine!) that would be great!

Thanks in advance!

Why do you have 5 trials of each type A and B when you have 2 and 4 levels of your IVs?

If you had 4 levels then you could have lists condition1=[1,2,3,4] and condition2=[1,2,1,2] and then shuffle them every four trials.

There are 400 trials in total (50 trials per condition), and I want the target image to switch every 5 trials. Also, I want it to be fully random - your solution doesn’t ensure that if I’m not wrong.

Thanks!

I thought you wanted each set of 5A5B to have equal numbers. If you just want it even across the whole experiment then you could create two nested arrays containing [[1,1],[1,2],…] for your 8 possible combinations. Then append then in a loop of 25 and shuffle. Use one for A and the other for B

Thanks for the response! I’ve managed to solve the problem with your suggestion. Also, for others who might be facing a similar problem, this thread might be helpful: Variables empty in online script (looping over dictionaries)