Howdy, Stranger!

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

Supported by

Create 12 unique random pairs from two different lists, and KEEP the pairing constant

Hello everyone,

I would like to know how to create 12 unique random pairs from two different lists of images, and keep this random pairing constant throughout the entire experiment (i.e. constant for a participant) but different between participants.

In my loop, I created three columns (see attached picture1):

-         The first one named “face”, is composed of 15 unique human faces named from “face_a”, to “face_o”.

-         The second column named “bio”, is composed of 12 pictures of very short biographies named from “bio_1” to “bio_12”.

-         The third list is correct_response (which in my case is g).

Then in the sequence using a keyboard_response and a sketchpad (see attached picture2), I would like to display at the same time one image from “face” and one image from “bio” (this represents one pair, for instance “face _b” with “bio_4”) and participants will have to press the G k to see the next pair (e.g. “face_d” with “bio_11”). 

In total, I would like to display 12 unique pairs per loop (but I have 15 faces, so some of them will not be used). And within a loop, each face and each biography can only be used once. (So, if “face_d” has previously been associated with “bio_11”, in the next trial, neither “face_d” nor “bio_11” can be used to create a new pair).

Because in my experiment, participants will have multiple occasions to learn the association between the faces and the biographies (throughout different loops), I would like the 12 pairs, once created, to remain constant throughout the entire experiment.

However, I would like the pairs to be different between participants. (For instance, if for the 1st participant “face_a” was associated with “bio_4”, for the 2nd participant “face_a” will not necessarily be associated with bio_4).

Despite my research, I really do not know how to do this, and I will greatly appreciate if someone could help me.

I hope my explanations are clear, otherwise do not hesitate to ask me for more precision.




  • Hi B,

    I am not entirely sure I understand your restrictions. You want for one subject to be the pairing of faces and biographies always constant? Or do you want to randomize in each block?

    The solution is almost the same either way, but requires some finetuning. I attach an example experiment that demonstrates the principle (it won't yet do what you want it to do!). Essentially in an inline_script you can define the lists that are possible (face_a ... face_o, and bio_1, ...., bio_12), and then randomly assign one to the other. Once you have that matching you can use it to access it, as if they were columns in the loop table. The only difference now, is that you have to index the correct item for an iteration in your loop. The easiest way to do that is to have a counter variable in the loop table (e.g. trial number), that pulls the first, second, third, ..., last item from that list you generated and assigns it to the variables you want to use in your sketchpad. Depending on your precise randomization schedule that inline_script either has to lie in the beginning of the experiment (where it is randomized exactly once), or in the beginning of every block, (where it is randomized as often as you have blocks).

    Hope this makes it a bit clearer.

    Good luck,


    Buy Me A Coffee

  • Hi Eduard,


    Thanks a lot for your reply, it helped me so much that I bought you a coffee :)

    In my experiment, I want the pairing to be constant for one subject, therefore, as you suggested, I put the inline_scirpt in the beginning of the experiment. It seems to work fine.

    I have a last question before I will be able to use my experiment with real subjects.

    I think my question resembles a bit of what you previously explained to me, but maybe a bit more complex.

    On top of the pairing of the faces and the biographies, I would like to pair three other lists together (I am not sure whether I need to pair the third one though).

    1) I would like to pair 4 words: " happy", "sad", "surprised", and "angry"; with 2) 4 positions on a sketchpad (for the words to be displayed, one word per position: position_a x = -670 y = 280; position_b x = 670 y = 280; position_c x = -590 y = 460;  position_d x = 590 y = 460) and 3) for each position I want to  assign a correct_reponse with the keyboard (s for position_a; c position_b; k position_c; n position_d).

    Basically, each face previously paired were in a neutral expression. I also have pictures of the same face in 4 different expressions (happy, sad, surprised and angry). I would like to display all the emotional versions of different faces (one by one) and display at the same time, underneath a picture, the 4 words (happy, sad, surprised and angry). Then participant will have to press the correct key allocated to the position that correspond of the emotion being displayed by the face.  

    I successfully created a block where the emotions have been placed by myself, please see the attached pictures (maybe it would be easier to understand).

    So, my concern is that I would like the 4 words (happy, sad, surprised and angry) to be displayed differently in the 4 positions between subjects. But I would like that once the 4 words have been placed, they remain constant throughout all blocks and trials (so constant for a subject; as in my previous question).

    However, it is important that the keys of the correct_responses associated with the positions are always the same for all the subjects. As you can see the 4 positions on the sketchpad represent a “rectangular shape”. Similarly, the 4 four keys also represent a “rectangular shape” on the keyboard. I chose this to be easier for participants, as for instance, postion_a represents the top left of the rectangle on the sketchpad and the s key represents the top left of the rectangle shpae on the keyboard.


    It would be extremely helpful if you could help me to do this. Especially because the variable trila_no is already used as a counter variable (for the faces and the biographies). And I do not know how to use positions with Opensesame.


    Thank you so much in advance.



  • Hi B,

    So, my concern is that I would like the 4 words (happy, sad, surprised and angry) to be displayed differently in the 4 positions between subjects.

    You can apply a similar randomization approach to the words, but because the locations are fixed, it is somewhat easier. Something like this should work:

    import random
    word_list = ['a', 'b', 'c']
    word_1, word_2, word_3 = word_list

    When you specify the sketchpad like you did in your last and secondlast screenshot, you can use those variables instead of hardcoding it. For example, instead of test=SURPRISED , you could do test=[word_1]. Then opensesame would fill in the word stored in that variable as text that is drawn at a certain position. You know what I mean?

    By the way, instead of response key mapping to screen location, you might want to consider using a mouse response and cursor ROIs. That might make response collection a little easier

    Does that solve your problem?


    ps, thanks for the coffee ;)

    Buy Me A Coffee

  • Hi @eduard

    Thanks a lot for your reply.

    I implemented the lines of code you suggested and the random positioning of the words works (I just changed a bit the last line from word_1, word_2, word_3 =word.list  to  var. word_1, var.word_2, var.word_3, var.word = word.list).

    My concern is that with my procedure I would prefer using keyboard and I have no idea of how to script to indicate the correct answer according to the random positioning of the words.

    I imagine there might be a way to match my variable called emotion (who display a picture of either happy, sad, angry and surprised emotion) and the variable word (who displayed the 4 words happy sad angry and surprised). But because of my random positioning I really do not know how to code such things, especially because is the position rather than the word that must indicate the type of correct key to press.

    Do you have any idea of how to do it?? That would be extremely helpful.

    Best regards,

  • Sorry, I don't get what exactly you mean. Do you want to know how to set the correct response? If so, what defines the correct response?

    Or do you want to know how to match the images to the words?

    Buy Me A Coffee

  • Hi @eduard ,

    Thanks a lot for your reply.

    Yes, I would like to set the correct response.

    There are 4 positions on the sketchpad for the 4 different words (“happy”, “sad”, “angry” and “surprised”) to be displayed in.

    The 4 positions are predefined manually (position 1 x=-670 y=280; position 2 x=-590 y=460; position 3 x=670 y=280; position 4 x=590 y=460) and I would like to assign a specific key to each position. For position 1 à s , position 2 à c, position 3 à k, and position 4 à n.

    Now to set the correct response, it depends on a) where the 4 words have been randomly placed before the experimental block and b) which emotion is being displayed on the picture in the center of the sketchpad (the emotion of the picture depends on a variable called emotion and could be either happy, sad, angry or surprised).

    I would like to set the correct response in such a way than when the emotion of the picture being displayed is, for instance, happy the correct response would be the key assigned to the position where the word happy has been placed. And so on for the three other emotions (when an angry picture is being displayed, the correct answer is the key assigned to the position of the word angry, etc….)

    For example, if the positions of the words are: position 1 = happy, position 2 = angry, position 3 = sad, position 4 =surprised.

    When the variable emotion is happy, a happy face would be displayed in the center of the sketchpad, and the correct answer would be the S key (because the word happy is in position 1, which has the assigned S key). For a next trial, let say the variable emotion is angry, then the correct answer would be the C key (because the word angry has been placed in position 2).

    I hope my explanation is clearer this time.

    It would be extremely helpful if you could help me to set my correct response.  

    Thank you very much in advance for your help and your time.

    Best regards,


  • Hi,

    I suppose what already works is:

    • assigning the words to the position
    • presenting the correct image (and have a variable that codes the emotion of that image)

    Now define the correct response you can compare the emotion of the image to the word at each position, and set respective correct response. For that the possible values of those two variables must be the same (e.g. both are [sad, happy, angry, envious]). For example, consider this:

    # assume the variable that codes the emotion of the image is var.emo
    if var.emo == var.word1:
        # key mapper is a dictionary mapping a position to a key, that you have to set up earlier
        # it could look like {1:'s', 2: 'a', 3: 'j', 4:, 'h'}
        var.correct_response = key_map[pos1]
    elif var.emo == var.word2:
         var.correct_response = key_map[pos2]
        # and so forth

    Does that clear things up?

    Buy Me A Coffee

  • Hi @eduard,

    Thanks a lot for your reply and your help.

    I added your lines of code and it seems to work regarding the variable "correct_response".

    However, the variables "accuracy" and "acc" are not correct, and it is really problematic as I would like to present to the participants their feedback after each block. I do not know why the variables "accuracy" and" acc "do not count properly the responses, nor what they are actually counting.

    I added in the inline script the variables "correct" and "response" (see the attached picture) which were previously ignored.

    Now the variable "correct" is counting properly the response.

    However, the variables "accuracy" and" acc "are still not correct.

    Is there a way to make it works?

    Or would it be possible to create a new variable to calculate the accuracy after each block to show to the participants, such as:

    New variable = ( sum of var.correct / 48) * 100  ?

    (48 is the number of trials in a block)

    Thank you very much in advance for your help.

    Best regards,


  • Both is possible. Why acc/accuracy don't work can have several reasons, you can share your experiment, and i can try to dig into what is the reason, but as you suggest, you can easily compute a new variable to calculate accuracy. Your formula is correct, you just need a variable that counts the number of trials and the number of correct responses and then you are set.


    ps. be aware that if you want to present feedback, you can't use a sketchpad (because of prepare-run strategy). You the feedback item for that purpose.

    Buy Me A Coffee

  • Hi @eduard ,

    Thanks a lot for your message. I tried to create my new variable but somehow it does not work :(

    I am trying to send you my experiment but I got a error message ( request failed with satus code413). Is there an otherway to send it to you?

    Otherwise, could you write the correct code to create a new "accurac"y variable please? I already got the variable that counts for the correct responses which is var.correct. And the number of trials is fixed is always 48.

    Thank you so much in advance for your help and your time. I really appreciate it.



  • Hi Benoit,

    Attached a simple example experiment demonstrating the use of a "personal" accuracy variable. Let me know if it is unclear.


    ps. in case uploading to the forum here doesn't work, you can always use some file sharing platform. e.g.

    Buy Me A Coffee

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