Randomly Selected Quadruplets of Ordered Elements -- How to do it?

Problem: you want to present sets of (e.g.) 4 stimuli. Each quadruplet of stimuli is ordered, but the quadruplets themselves must be picked randomly.

Right, yes, how to do it? This is not immediately evident with PsyScope.


The Quadruplets simple template presents sets of 4 ORDERED  stimuli RANDOMLY. That is, it picks a quadruplet randomly and it presents the four items in sequential order.

To achieve this, you have to script lists directly.

REMINDER: Lists in the graphical interface and script lists are different entities. Lists in the graphical interface are really FACTORS. Lists in the script are honest-to God(des) lists. There are lots of things that hinge upon this subtle difference. See the PsyScope manual, pp. 129 and 329 to understand the difference.

  1. 1. We create lists of quadruplets as separate lists in the script. They are defined in the #> TrialManagerVariables section of the script. The lists are named  L1, L2, etc, and contain our quadruplets. All are set as sequential in accesstype:

L1:: a1 a2 a3 a4


L2:: b1 b2 b3 b4


L3:: c1 c2 c3 c4


L4:: d1 d2 d3 d4


2. Then we create a  list (Myrand) that contains numbers for the quadruplets: 1, 2, 3, etc. This is accessed randomly:

Myrand :: 1 2 3 4


3. A third list (ListOfLists) contains the quadruplets, composed randomly. Here the some trick is to compose the names of the lists of quadruplets as elements of the lists . The fact that the number is accessed randomly assures that the quadruplets will be chosen randomly:

ListOfLists:: @strcat(L,(access(Myrand)))  @strcat(L,(access(Myrand))) @strcat(L,(access(Myrand))) @strcat(L,(access(Myrand)))


Let me better explain the "name" trick. I use the strcat   function, which composes strings. The first element of strcat is the letter L. The second element is obtained by the function Access, which gets a random element (without replacement) of the list Myrand . As Myrand   contains the number 1, 2, 3, and 4, strcat will finally give, for example, L2, or L4.

Following our example, L4 is the name of a list. Thus @L4 will return all the elements of that list. Hence, ListOfLists will contain all the elements of all the Ln lists, ordered within lists (because each L1, L2, L3, L4 has sequential access), but randomized between lists (because the Myrand list has random access).  As ListOfLists has sequential access, no other randomization will occur and therefore the items of ListOfLists will be presented as they were composed.

4. To preserve a trace of what happens, I copy ListofLists to   ListOfLists2 , so that one can see the actual order of items after the experiment (really this can be done in several other ways, You can check the data file to see what items have been sent). To do that, I make a n event (SetUpLists) that does nothing but erase ListOfLists2 and copy again ListOfLists to ListOfLists2 . This is obtained with another trick, the null function.

Take a look at the event SetUpLists


EventType:   null(DeleteAllToks(ListOfLists2) AppendTok(ListOfLists2  @ListOfLists)) Null

Duration: 500

When PsyScope encounters null() , it executes what is inside before continuing. So when this event is called, first all tokens of ListofLists2 are erased with a DeleteAllToks call. Then, AppendTok looks at what there is in ListOfLists, and writes it to ListofLists2.

5. It is now sufficient to create an event  with the content of ListOfLists2 (really, also of ListOfLists if you want) as a stimulus (or as whatever you want the quadruplets for). In the script , this is done at the event Event1:


EventType:  Text

Duration: 500

Stimulus:   Access(ListOfLists2)

Its stimulus is taken from ListOfLists2 via Access .

You can check that you can also assign other stimuli randomly (e.g. pictures) to other events in the script.

That is it. The script Quadruplets script does the same thing, but also shows that if you use another stimulus associated to another list, because the lists I used are defined in the script (ie, they are not factor lists), the list of the new stimulus and the lists I defined do not cross. Therefore, all stimuli are presented correctly once.

To adapt this technique to  your script, you have to add the little lists separately (L5, L6 and so on if you need more than four quadruplets, or quintuplets instead of quadruplets, and so on), add the corresponding numbers in Myrand , and add other Strcat conditions to ListOfLists--one per quadruplet list.

Back to the PsyScope X page