Nested Randomized Loops without Replacement

Hello,

I know similar questions have asked been asked before, but I have gotten myself quite confused with potential solutions. So I’m hoping to describe my problem and hopefully be pointed towards a clean solution I can try to implement.

I am looking to present two different tasks (Task 1 & Task 2) twice, under two different conditions (Cond 1 & Cond 2). Each Task has 4 possible trials (Task 1: ABCD; Task 2: EFGH). I want to show 2 of the 4 trials for each task under Condition 1, and then the remaining 2 trials for each Task under Condition 2.
For example, a participant might see combinations such as:

  • Condition 1:
    ** Task 1: AC
    ** Task 2: EG
  • Condition 2:
    **Task 1: BD
    **Task 2: FH

Condition blocks 1 & 2 need to be randomized, but Tasks should remain in order (1 before 2).

Any idea of how to elegantly do this? I am using the Builder for online use. I can use code components if needed, but I was getting confused with that as well.

Thanks in advance!

Here’s a solution that could work for you.

Begin Experiment

conditions = [1,2]
shuffle(conditions)
tasks = [1,1,2,2,1,1,2,2]

task1 = ['A','B','C','D']
shuffle(task1)

task2 = ['E','F','G','H']
shuffle(task2)

thisCondition = 0
thisTrial = ''

Add a loop called trials with no spreadsheet and nReps = 8

Begin Routine

if trials.thisN < 4:
     thisCondition = conditions[0]
else:
     thisCondition = conditions[1]

thisTask = tasks[trials.thisN]
if thisTask == 1:
     thisTrial = task1.pop() # pop assigns and then removes final item in list
else:
     thisTrial = task2.pop()

What you do with thisCondition (1/2), thisTask (1/2) and thisTrial (A/B/C/D) is then up to you.

1 Like

Thank you! This worked great with some tweaking. The pop() function is really useful.

1 Like