Randomization not repeated

In this experiment, participants are presented with color words written in different ink color. The
participants are required to name the ink color of the stimuli. Each respond of the participant is
recorded as a WAV file in each trial and also the reaction time is recorded.
Every trial includes: a fixation cross presented for 0.5 ms, then the stimulus (color word)
presented for 2 seconds and a blank screen presented 0.5 ms. The voice recording and reaction
time calculation occurs during color word presentation.
The experiment includes several categories of color words presented as jpg image files which are
placed in different folders (see line 33 in the m file):
ing_uyumlu_dosyalar = dir('ingilizceUyumlu/');
ing_uyumsuz_dosyalar = dir('ingilizceUyumsuz/');
tr_uyumlu_dosyalar = dir('TurkceUyumlu/');
tr_uyumsuz_dosyalar =dir('TurkceUyumsuz/');

The folder named “ingilizceUyumlu” includes the following images:
MCC.JPG; MJJ.JPG; MSS.JPG; MZZ.JPG

The folder named “ingilizceUyumsuz” includes the following images:
MCJ.JPG; MCS.JPG; MCZ.JPG; MJC.JPG; MJS.JPG; MJZ.JPG; MSC.JPG; MSJ.JPG;
MSZ.JPG; MZC.JPG; MZJ.JPG; MZS.JPG

The folder named “TurkceUyumlu” includes the following images:
TKK.JPG; TMM.JPG; TSS.JPG; TYY.JPG

The folder named “TurkceUyumsuz” includes the following images:
TKM.JPG; TKS.JPG; TKY.JPG; TMK.JPG; TMS.JPG; TMY.JPG; TSK.JPG; TSM.JPG;
TSY.JPG; TYK.JPG; TYM.JPG; TYS.JPG

The order of presentation of image files is kind of predetermined (see line 50). In particular, it is
predetermined which folder to be used in each trial:
experiment_order = {
{2, randi(count_ing_uyumlu), 'bs'}; %1
{1, randi(count_tr_uyumsuz), 'gd'}; %2
{1, randi(count_tr_uyumsuz), 'td'}; %3
{0, randi(count_tr_uyumlu), 'td'}; %4
{2, randi(count_ing_uyumlu), 'gd'}; %5
{0, randi(count_tr_uyumlu), 'gd' }; %6
{3, randi(count_ing_uyumsuz), 'gd'}; %7
{3, randi(count_ing_uyumsuz), 'td'}; %8
{2, randi(count_ing_uyumlu), 'td'}; %9
{1, randi(count_tr_uyumsuz), 'gd'}; %10
{1, randi(count_tr_uyumsuz), 'td'}; %11
{0, randi(count_tr_uyumlu), 'td'}; %12
{2, randi(count_ing_uyumlu), 'gd'}; %13
{3, randi(count_ing_uyumsuz), 'td'}; %14
{3, randi(count_ing_uyumsuz), 'td'}; %15
{0, randi(count_tr_uyumlu), 'gd'}; %16
{2, randi(count_ing_uyumlu), 'gd'}; %17
{1, randi(count_tr_uyumsuz), 'gd'}; %18
{1, randi(count_tr_uyumsuz), 'td'}; %19
{0, randi(count_tr_uyumlu), 'td'}; %20
{2, randi(count_ing_uyumlu), 'gd'}; %21
};

Request:
As it is, the code chooses a random image from a folder in each trial. However, there is a
possibility that some stimuli with similar features, or the same exact stimulus could be presented
in successive trials. Thus, there is a need of restricting this possibility.
As we talked, this could be done by defining some stimulus clusters and writing “if…else” codes
restricting choosing stimuli from the same clusters in successive trials.
The clusters are the following:

BlueInkColor: MSS.JPG; MCS.JPG; MJS.JPG; MZS.JPG; TMM.JPG; TKM.JPG; TSM.JPG; TYM.JPG
GreenInkColor: MZZ.JPG; MCZ.JPG; MJZ.JPG; MSZ.JPG; TYY.JPG; TKY.JPG; TMY.JPG; TSY.JPG
RedInkColor: MCC.JPG; MJC.JPG; MSC.JPG; MZC.JPG; TKK.JPG; TMK.JPG; TSK.JPG; TYK.JPG
YellowInkColor: MJJ.JPG; MCJ.JPG; MSJ.JPG; MZJ.JPG; TSS.JPG; TKS.JPG; TMS.JPG; TYS.JPG;

BlueColorWord: MSS.JPG; MSC.JPG; MSJ.JPG; MSZ.JPG; TMM.JPG; TMK.JPG; TMS.JPG; TMY.JPG
GreenColorWord: MZZ.JPG; MZC.JPG; MZJ.JPG; MZS.JPG; TYY.JPG; TYK.JPG; TYM.JPG; TYS.JPG
RedColorWord: MCC.JPG; MCJ.JPG; MCS.JPG; MCZ.JPG; TKK.JPG; TKM.JPG; TKS.JPG; TKY.JPG
YellowColorWord: MJJ.JPG; MJC.JPG; MJS.JPG; MJZ.JPG; TSS.JPG; TSK.JPG; TSM.JPG; TSY.JPG

Finally, those images who have the exact same name (e.g., MSS.JPG) should not follow in
successive trials.

The best way to achieve this I think is to create a blank list at the start of the experiment, then when an image is presented, .append it to the list. That way, you can have something like this when picking an image:

chosenImage = functionToChooseImage()
while chosenImage in previouslyChosenList:
    chosenImage = functionToChooseImage()

Alternatively, you can use .pop() to remove the image from the list chosen from when it’s used, so that it can’t be chosen again.

Actually this is for a friend of mine, could you help me on the part how can I create a blank list and append to it and can I pop the same way as in any other programming languages. Thanks a lot every single line is appreciated.

items =
items.append(item)
thisItem = items.pop()

i still need some help with this since I am super new in psychopy appreciate it.

Please could you post screenshots and code for your current best attempt, along with error messages – or specifics of what isn’t working?

So basically that is what she told me she runs and the code approx where we need to implement the not repeated randomisation:




Basically she has 64 different simulis, one group is [32] for colors the other group [32] for words of those colors. What she wants is after eg. Blue (with word or with colour) she does not want blue to be repeated on the next trial.

Here is the code just in case you want to check:









Sorry – but that code is beyond the limit of what I can easily read. It doesn’t look like Python (no colon at the end of the if statements), but it doesn’t look like JavaScript either.

I have limited experience of coding PsychoPy experiments from scratch, preferring to use Builder plus custom code components.

1 Like

I think this is done in matlab though so i do not know what to say myself. But she needs our help for sure.