Howdy, Stranger!

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

Supported by

Constrain Loop Randomization

Hi all,
I am programming an experiment in which i need to applied 2 different constrains to Loop randomization.
Specifically I want

1) Make repetitions of the same Condition(Joint or Solo) are separated by at least 5 cycles. I did it following the instructions here and it works.
2) At the same time, I want make that the loop always start with a Condition = Joint cycle.

How do I implement the second constrain?

Thank you!


  • Hi Eris,

    The easiest way to accomplish this would be to simply start with loop of length 1 in which Condition is 'joint'. And then you have a second loop in which you have more trials, and in which you use pseudorandomization. Does that work?


    Buy Me A Coffee

  • Hi Sebastian,
    Let's say that yes in general it works, but not in my specific case.

    I am looking for a solution in python. I f I find it i will post it

  • Hi Sebastian,

    I've tried to use the contrain comand with mindist

    constrain Condition mindist=5.

    But it doesn't work. It could be to the fact that i am using phyton 3?


  • Hi Eris,

    The constrain command is not Python code, but OpenSesame script, which you need to add to the script of the loop item. You can see how this works (but with another command) in this screencast:

    Does that clear things up?


    Buy Me A Coffee

  • Hi Sebastian,
    Thanks for the video. But This is not what I need.
    I need the constrain command, which are explain in the manual

    I've tried both commands, here is what happens:
    1) with constrain Condition mindist=5 -> the experiment run, but it get stucked at the first item of the sequence. Note that it doesn't crush but it stucks

    2) with constrain Condition maxrep=5 -> the experiment run well but it doesn't constrain the randomization.So basically it's like the command is ignored.

    Here is a copy of my loop script. I can't upload the program 'cause there is an external device integrated.


  • Hi Francesca,

    With two conditions (joint and solo) it is not logically possible to have a minimum distance of 5 between repetitions! That's why OpenSesame hangs: it's trying to figure out a solution, which doesn't exist, and it takes a while before a timeout occurs. (So it won't crash indefinitely.)

    So I would take a step back and formulate clearly for yourself what you're trying to accomplish exactly. Can you give an example of a loop table that meets your criteria?


    Buy Me A Coffee

  • Hi @sebastiaan,

    I'm posting here because that's exactly what I'm trying to accomplish in my experiment, too: I have 10 blocks as loops with items of different conditions, the order of which I constrained with mindist and maxrep. This works fine. Now I need to add another constrained, namely the same as the @Eris posted as constrain 2) above: Each block should start with condition = filler. And then proceed through the rest of the item list.

    You suggested to add another 1-item filler loop before the actual loop, right? But then I wouldn't be able to pick this first item randomly from the fillers, and my experimental structure is quite heavy already. Is there another way, maybe using the constrain command or a bit of code in the loop?

    I'd be happy for any advice!



  • Hi @schuetzin ,

    This is an interesting scenario. You cannot directly constrain the value of the first row, so you need some kind of workaround. What I would do is add an inline_script just before the loop that needs to be constrained. In the prepare phase of the script, do something like the code below. Basically, it adds a maxrep constraint programmatically and ensures that the first value for the condition column is 'A'. (The specific values and constraints of course depend on the experiment.)

    To make this work, you need to set the order of the loop to sequential and don't add any constraints or other operations to the loop itself.

    Do you see the logic?

    from pseudorandom import Enforce, MaxRep
    # Get the datamatrix from the to-be-constrained loop
    dm = items['constrained_loop'].dm
    # Create an Enforce object, and contrain the minimum distance for condition
    while True:
        ef = Enforce(dm)
        ef.add_constraint(MaxRep, cols=[dm.condition], maxrep=1)
        dm = ef.enforce()
        # To make sure the first condition is A, check it explicitly here, because
        # there is no corresponding costraint to implement this
        if dm.condition[0] == 'A':
    # Set the datamatrix from the to-be-constrained loop
    items['constrained_loop'].dm = dm

    — Sebastiaan

    Buy Me A Coffee

  • Great, this does the trick! I added some MinDist constraints after the MaxRep constraint and got the pseudorandomised order I need. Thank you so much.

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games