#### Howdy, Stranger!

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

Supported by

# [solved] randomizing a sequence of four blocks

edited July 2013

Hi Sebastian.

I have this experimental structure:

``````My experiment
- experimental loop
-- block sequence
--- block sequence 1
--- block sequence 2
--- block sequence 3
--- block sequence 4
``````

Inside each block sequence there is a trial loop with a trial sequence inside.
I want to randomizing the four sequences inside the block sequence, but simply setting the random order option in the experimental loop doesn't work (I don't know why...).

In this post I have read that a solution for a similar problem is to set a order variable (in my case with the values 1, 2, 3, 4) in the experimental loop, an then use the "run if" statemant for all the permutations of the blocks order. But in my case I have to set 4! = 24 permutations! (

There does exist an easier method to randomizing?

Cheers,

Andrea

## Comments

• edited July 2013

Hi Andrea,

Right, if you set a loop to random, it will only randomize the order of the loop. The order of the items in a sequence is always fixed. Still, you can mimic a random sequence quite easily with a simple inline_script. See below, some instructions are added as code comments.

Cheers!
Sebastiaan

``````from random import shuffle

# Uncomment for 0.25 and before
# exp = self.experiment

# Create a list of items that are part of the sequence
# These items must be present somewhere in the experiment.
# An easy solution is to add them to a dummy_sequence at
# the start of the trial and set the 'run if' statement of
# the dummy_sequence to 'never'.
item_list = ['item1', 'item2', 'item3', 'item4']

# Randomize the item order. Of course you can also do more
# complicated things, such as have the order depend on the
# subject nr, etc.
shuffle(item_list)

# First, prepare all items
for item in item_list:
exp.items[item].prepare()

# Now run them!
for item in item_list:
exp.items[item].run()
``````

• edited 7:59AM

I have tried it just now and it works like a charm. You are the Genie of the Lamp.

Thank you very much, Sebastian.

• edited 7:59AM

Hi,
I am brand new in Open Sesame and I know nothing about Python (I have been using SuperLab before). I have been trying to what Sebastiaan suggests, but I am not getting results. Could somebody explain it to me like "Open Sesame for dummies"?
I need to run several blocks of 36 sequences (1 fix point+1 sentence+ 1 question about the previous sentence) in a random way (the presentation of the 36 pairs of sentence+question must be random), and collect RTs and yes/no answers.
I understand the structure is pretty much like the one Andrea has, but with more sequences.
And another thing: I am having problems with the excel with the collected data. It seems to be all mixed up and RTs are not recorded (or so it seems)...and I don´t know how to solve it.

Thanks!
Gabi

• Hi dear
please I,m looking for your help
i have 10 universities i want to do the randomization to allocate it for intervention group and control group and i want to use the block methode who can i do it please

• Hey Sebastian,

It tried to use the code you provided above. However, I don't understand this part:

```# Create a list of items that are part of the sequence
# These items must be present somewhere in the experiment.
# An easy solution is to add them to a dummy_sequence at
# the start of the trial and set the 'run if' statement of
# the dummy_sequence to 'never'.
item_list = ['item1', 'item2', 'item3', 'item4']
```

My experiment looks like that:

And my goal is to randomize available_unavailable_mother, lovable_unlovable_self, and avialable_unavialble_father.

Thank you in advance.

Best, Laura

• Hi @L_Geissert ,

You could put the three `sequence` s inside another container`loop` - `sequence` structure. Then, in the container `loop` , you create a variable that determines which of the three `sequence` s is executed. And in the container `sequence` you use a run-if statement to determine which of that (sub) `sequence` is executed. Does that make sense?

In the example below I used `sketchpad` s. In your case, you would replace these by the three `sequence` s that you want to randomize.

Cheers!

Sebastiaan

• Hey Sebastiaan,

it makes sense, thank you so much!

Best,

Laura

Sign In or Register to comment.