[solved] Equal number of trials when randomising
Hi all,
I'm running a simple experiment that requires people to read words off the screen. The aim is to test perception thresholds for different font colours. I have 255 words and 15 different font colours and I want each word to be displayed in a randomly chosen colour. Therefore, for each colour I would like to have 17 words randomly picked from the list.
To do so, I created a block with a list of words (255) that runs a sequence with 15 sketchpads, each using different font colour. Before the sketchpads there is a short script I wrote to create a variable [n] that has value of a random integer (1,15). If [n] = number of sketchpad, the sketchpad gets run.
Unfortunately, this method results in different frequencies of calling each sketchpad, so I'm not getting a nice 17 words per each sketchpad.
I bet there is a better solution to this, but I'm not very fluent with OS.
I would really appreciate your help!
Thanks,
Jarek
Comments
Hi Jarek,
To make sure that every sketchpad is ran exactly 17 times, you could use the built-in Python function
pop(), which draws one item from a list without replacement. This way, you can keep popping sketchpad numbers until the list is empty (i.e. until every sketchpad is ran 17 times).To achieve this, firstly append an inline_script item to the beginning of your block sequence where you define a list containing the sketchpad numbers for all trials in a given block (i.e., seventeen 1's, seventeen 2's, etc., until 15):
Next, change the code in the inline_script in your trial_sequence where you define the value of the variable n:
Does this help?
Best,
Lotje
Did you like my answer? Feel free to

Hi Lotje,
This looks great and works great too, thank you very much!
Just to make sure I understand what's going on:
does this little bit
l = range(1,16)*17
create 17 lists of 15 elements? If so, in case I would like to run 3 blocks of 255, could I just change it to
l = range(1,16)*51
Would this be also correct?
Best,
Jarek
Hi Jarek,
Good to hear that it works.
No, it creates one list containing 255 items. Seventeen 1's, seventeen 2's, etc.
Actually, the corresponding piece of code might be easier to understand when it is rewritten to:
This will return
in the debug window.
This will return:
And
will print '
i.e. the length of the list.
As you see, printing information to the debug window can be really helpful when using Python inline coding.
Yes, that would work. But note that after randomising the resulting list, you will not be sure that every sketchpad occurs equally often within a given block (but only that it occurs equally often across the 3 blocks). That's why I advised to (re)set the list at the beginning of every block sequence (in which case all sketchpads do occur equally often within a given block).
Does this make sense? Please let us know if you have any further questions.
Cheers,
Lotje
Did you like my answer? Feel free to

HI Lotje,
Yes, that makes perfect sense. In my case I want to have equal numbers across all trials, so I can go for one big list.
Thanks again for helping me,
Jarek