Howdy, Stranger!

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

Supported by

[solved] Pseudorandom order

edited January 2014 in OpenSesame


I would want that the program follows a specific order of trials presentation: I had created it yet. Is it possible (and in this case, how I could introduce it?) or is it necessary to have a block of sequence for each trial?




  • edited 7:56PM

    Hi Frederica,

    I would want that the program follows a specific order of trials presentation: I had created it yet.

    I'm not sure I understand your question? Do you mean that you would like to run your trials sequentially, rather than in random order? In order to do that you need to set 'order' to 'sequential' in the loop item that contains your trial sequence.

    is it necessary to have a block of sequence for each trial?

    Well, it's not strictly speaking necessary. A trial could also consist of a single item. But usually a trial consists of multiple items, and in that case you would put all the items that comprise the trial into a sequence.

    Does this answer your question at all?


  • edited February 2012

    Dear Sebastian,

    I’m not sure I explained very well my problem. So, I tried again but this time with more details.

    I want to use the program as a support for my experiment with minibird. In this experiment I will ask subjects to do a direct pointing movement towards a target. The target is presented on a screen and the presentation is controlled by Opensesame program.

    I have 13 different position of the target in horizontal space and because I need to be very very precious, I decided to construct 13 pictures, one for different position: I will show them in widescreen modality , setting correctly the display resolution in the Opensesame program.

    If I understood correctly, the term “sequence” refers to “what happens in one trial”. So in my case:

    Sequence = 1 text display – 2 sketchpads – 1keyboard_response – 1 logger.

    About the 2 sketchpads: the first is white empty screen; after 2 secs, the second skechtpad in which the picture is showed. All these things are under the label “LOOP”.

    And here, my doubt! As I told you, I have a pseudorandom order (basically I want to avoid that the same position is presented for two trials consecutively): every position is showed for 4 times; overall 52 trials.
    Have I to construct 52 loops (in every loop, in the second sketchpad I put the picture of interested)? Or could I just create one loop (and so one sequence) and give the program the list of trials to follow? for example:


    Trial 1 – picture 2

    Trial 2- picture 1

    Trial 3 – picture 3

    Trial 4 - picture 1


    If the second hypothesis is correct, where has this list to be introduced? In the variables setting space (point 3 of OpenSesame Tutorial?).

    Thank you in advance,


  • edited September 2013

    Hi Frederica,

    Ok, so if I understand correctly you want to create a trial sequence that is more-or-less random, but has the restriction that the same image shouldn't be shown twice in immediate succession. Is that correct?

    That's a bit tricky, but an inline_script should do the trick. First, at the start of the experiment, you create a list of (picture) numbers that meets your criteria.

    # Put this script in the prepare phase of an
    # inline_script item at the start of the
    # experiment.
    from random import shuffle
    global pic_list # Make pic_list global so we can use it later
    pic_list = range(1,14) # Create a list of nuber 1 to 13
    pic_list *= 4 # Repeat every number 4 times
    shuffle(pic_list) # Randomize the list
    # Now check if a number is repeated immediately (e.g, 9, 2, 2, 5)
    # and randomize until this is not the case
    while True:
        reshuffle = False
        for i in range(len(pic_list)-1):
            if pic_list[i] == pic_list[i+1]:
                reshuffle = True
        if not reshuffle:

    Then, at the start of a trial, you select one number and set a variable that you can use in, for example, a sketchpad, like so [my_pseudo_random_pic]. This assumes that you have named your images image01.png through image13.png.

    # Put this code in the prepare phase of an inline_script
    # item at the start of the trial sequence.
    global pic_list # Access the pic list
    pic = pic_list.pop() # Get a pic number
    # Set the variable so we can use it in a sketchpad
    self.experiment.set("my_pseudo_random_pic", "image%.2d.png" % pic)

    Regarding the loop: You don't have to define a loop variable for the picture numbers, because we handle that using these inline_scripts. But you should make sure that the block_loop has the correct length (i.e., 52).

    Hope this gets you started!


  • edited 7:56PM

    Thank you so much!!



Sign In or Register to comment.