# Counterbalancing Randomization Within and Across Loops

Hi all,

I’m trying to figure out how to counterbalance a repeated condition across two blocks of trials without repetition. I’ve looked through the forum posts and demos but haven’t found anything quite like this yet (but please correct me if I’m wrong).

For instance, I have my excel file of 4 trials: A, B, C, D. I want to present two blocks of these trials in random order, which might look like this: block 1= [A, C, B, D] and block 2 = [B, A, D, C].

Within each block 1/2 of the trials should be in yellow font, whereas the other 1/2 should be in red font. In the following block, the trials that were presented in yellow font should be shown in red, and the trials previously shown in red font should be shown in yellow font. So for instance, if A and D are red in block 1, A and D should be yellow in block 2. Likewise, if B and C are yellow in the first block, B and C should be red in block 2.

Note that this is different from counterbalancing separate blocks of font colors (e.g., randomize the color of the 4 trials as red in block 1 followed by yellow in block 2, or vice versa). There are some great examples out there for this type of randomization, but I’m not sure how to go about adapting that to my needs. Also note I’m looking for a solution that would work online with Pavlovia.

Does anyone have any ideas on how to go about counterbalancing a randomization like this within and across loops?

Thanks in advance for any help!