But, anyway, would it assure that the items (experimental and fillers) are randomly selected for each participant?
Yes, the script is run anew for each participant, so the
sort(...) parts in particular will give you a (possibly) different output for each participant. This means that the pair of “A” trials will be random and (possibly) different for each participant, same thing for the pair of “B” trials and so on. The order in which those pairs are run will also be random and (possibly) different for each participant: one participant for example will see “E,E,filler-4,filler-1,C,C,…” and another one could see “C,C,filler-2,filler-3,A,A,…”