Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Randomize trial in a sequence and repeat the same sequence two times

Hi, I have a sequence with 4 items. I need to randomize items in the sequence e show the sequence two times. For example, if my trials are "A, B, C, D" I need to randomize them (e.g. B, C, A, D) and then show this sequence two times (B, C, A, D, B, C, A, D).
In OpenSesame I set an experimental loop with 4 cycles in random order. Then, how can I repeat the same sequence two times?

Comments

  • Hi,

    That's an interesting scenario. There are multiple ways to solve it, but here's what I would do. First, in your loop, define your condition variable in terms of other variables: condition0, condition1, etc. Keep a sequential order, and set repeat to 2:

    Then, before the loop, insert an inline_script in which you define the variables condition0, etc. such that they correspond to your conditions ('A', 'B', 'C', and 'D) in a random order.

    import random
    
    conditions = ['A', 'B', 'C', 'D']
    random.shuffle(conditions)
    
    var.condition0 = conditions[0]
    var.condition1 = conditions[1]
    var.condition2 = conditions[2]
    var.condition3 = conditions[3]
    

    Do you see the logic here?

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Hi Sebastian,
    Thanks for your response. I'm not very good in Python, so I'll show you my experiment:

    On the left you can see the experimental sequence, then my experimental loop (is that correct?). Then i wrote a inline_script as you told me:

    Could you help me in a more specific way?

    Thanks a lot

  • Hi,

    What exactly is the problem? Your script and structure seem to be fine. (Maybe you could move your script for the run to the prepare phase of your inline_script). Are there any error messages?

    Eduard

  • The problem is that trials are not randomized. It shows times 25, 35, 45 and 55 and then repeats.

  • Oh, I see. Well, this is because you do randomize only your condition variable but not the durations of the conditions. They are hardcoded.

    You can try coding all your variables in a similar way:

    import random
    
    order = [1,2,3,4]
    conditions = ['A', 'B', 'C', 'D']
    durations = [25000,35000,45000,55000]
    random.shuffle(order)
    
    # the conditions
    var.condition0 = conditions[order[0]]
    var.condition1 = conditions[order[1]]
    var.condition2 = conditions[order[2]]
    var.condition3 = conditions[order[3]]
    
    # the durations
    var.durations0 = durations[order[0]]
    var.durations1 = durations[order[1]]
    var.durations2 = durations[order[2]]
    var.durations3 = durations[order[3]]
    
    # etc..
    

    Alternatively, you have to add another inline_script to the trial sequence and in that one set variables depending on the condition you are in.

    Does that make sense?

    Eduard

Sign In or Register to comment.