# Randomising the selection of different series, while keeping items within each series sequential

**URL:** <https://discourse.psychopy.org/t/randomising-the-selection-of-different-series-while-keeping-items-within-each-series-sequential/45340>\
**Category:** Builder\
**Created:** [August 7, 2025, 2:37pm UTC](https://discourse.psychopy.org/t/randomising-the-selection-of-different-series-while-keeping-items-within-each-series-sequential/45340 "2025-08-07T14:37:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![reyams](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@reyams](https://discourse.psychopy.org/u/reyams)\
**Post date:** [August 7, 2025, 2:37pm UTC](https://discourse.psychopy.org/t/randomising-the-selection-of-different-series-while-keeping-items-within-each-series-sequential/45340/1 "2025-08-07T14:37:18Z")

</div>

**OS** (Win11):  
**PsychoPy version** (e.g. 2024.2.4 Py 3.8):  
**Standard Standalone Installation? y**  
**Do you want it to also run online? n**  
**What are you trying to achieve?:**

I am doing a recognition memory test with multiple series of images gradually getting closer to a “target” item. I would like the items _within_ the series to be sequential, but the order of the series’ to be random - i.e. if I’ve got 3 series (S1,S2,S3) each consisting of 3 items (I1, I2, I3), I’d like the items to stay in order (always I1, I2, I3) but the series to be randomly be selected in different orders (e.g. S2, S1, S3; S3, S1, S2; etc). All series will eventually be shown to every participant

**What did you try to make it work?:**

I started off with making a routine for each series and then attempting to loop over it selecting randomly, but that’s both impactical (my real experiment will have 50 series) and just doesn’t work (I can see why it doesn’t work, I’m not actually dynamically referring to anything and just sticking a loop over a bunch of routines and selecting “random” on the loop isn’t going to change that)

I tried making a truth matrix with only one ‘1’ per column but this also didn’t work - I suspect because I was applying it to a nonsensical loop.

At the moment my experiment has just one ‘trial’ routine and then 2 nested loops like this, which I think is correct

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/9/f979016ae1032f913a22f8ec0839d7f69de464e9.png)

However, I can’t work out what needs to go in the excel file, where the images should be stored (I assume just on the same filepath?), and what I should put in the “Image” box on image properties and what I should put in the “condition” box for each loop. I’ve attached screenshots of what I currently have at the end.

I currently have this excel file as the conditions for ‘images’ loop (‘image\_refs.xlsx’). It repeats in the same pattern all the way down, though please note that the series are variably either length 4 or length 8. I don’t _think_ that will impact how I build the experiment but I’m (evidently) not very knowledgeable about this, so I wanted to mention it in case it is relevant

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/4/84fe166c6a836f656d828781f6c69da2e43e8637.png)

I also have this excel sheet for the outer loop (‘outer\_loop.xlsx’) based on advice from here: [Sequential and Random Selection at the same time - #7 by Michael](https://discourse.psychopy.org/t/sequential-and-random-selection-at-the-same-time/10844/7) , but am unsure whether it’s actually useful, and definitely don’t know how to make it useful! I fear part of the problem is me missing some fundamentals…

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/9/c91f2ed9b53c36fbb70a136c173051a5a764c606.png)

I’ve pasted the image properties, and the properties for both loops, as I currently believe this is where the problem is.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/3/038990687d4be5685b22848175575b344be615aa.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/3/93c6e5aa46d0b4bb97ec4f086247c291c4946dc8.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/2/328456d3b79cf70da302781916dde636cea7c2af.png)

**Link to the most relevant existing thread you have found:**

the below thread is somewhat similar but missing the ‘sequential series’ aspect

> [@I am asking assistance with my experiment, I have been trying to randomise/loop images but they never appear as random, only one of them appears 4 times instaead of 4 different images appearing in random order](https://discourse.psychopy.org/t/i-am-asking-assistance-with-my-experiment-i-have-been-trying-to-randomise-loop-images-but-they-never-appear-as-random-only-one-of-them-appears-4-times-instaead-of-4-different-images-appearing-in-random-order/44327/5):
>
> Hi, I hope you are well. So this is how my experiment has been designed thus far: I created a folder Inside the folder there is a folder that has 4 images There is an excel that has the 4 components and 1 parameter The experiment There is a welcome routine that has a welcome message Instruction routine that has instructions There is a loop Inside the loop there is the trial routine which has the image (this image is the one that appears 4 times when i run the experiment) From…

I got the command “$eval(“target” +$expInfo[‘target’])” from the below, but this also isn’t quite right

> [@Trying to use different excel columns based on participant number](https://discourse.psychopy.org/t/trying-to-use-different-excel-columns-based-on-participant-number/3601):
>
> So Im trying to display text using a different column of data depending on the provided participant number. Columns are set up as “Participant1” “Participant2” etc. I’m just using a small tidbit of code in a text stimuli presentation (not the code builder) $(“Participant” + $expInfo[‘participant’]) It is getting the participant number perfectly fine, and combining them correctly, but then it isn’t using them to access the excel file, it is just printing them as a string(as Participant1, Part…

This is similar but opposite to my issue

> [@Sequential and Random Selection at the same time](https://discourse.psychopy.org/t/sequential-and-random-selection-at-the-same-time/10844/7):
>
> I read your original post as indicating that there were successive blocks of trials of the same type, rather than a single block of trials of interleaved trial types. A double-loop arrangement won’t help with this. What is probably easiest is a single loop, and with the conditions and image names determined in code rather than in a conditions file. Insert a code component (from the “custom” component panel) and put something like this in the “begin experiment” tab, to create lists of image name…

**What specifically went wrong when you tried that?:**  
Error message:

DEPRECATION Couldn’t find image eval(“target” +$expInfo[‘target’]); check path? (tried: C:\Users\Rey - Work\Documents\psypy\_7\_8\_25\eval(“target” +$expInfo[‘target’]))

---

<div class="post-metadata">

**Author:** ![stanley1O1](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@stanley1O1](https://discourse.psychopy.org/u/stanley1O1)\
**Post date:** [August 7, 2025, 7:19pm UTC](https://discourse.psychopy.org/t/randomising-the-selection-of-different-series-while-keeping-items-within-each-series-sequential/45340/2 "2025-08-07T19:19:37Z")

</div>

Dear Reyams,

The way I have done things similar to yours is like this.

For your outer loop, just have a set of excel file paths as each row. Then each excel file is just a whatever the trials you want in each “block”. The loop conditions for the inner is the reference variable in the outerloop spreadsheet (e.g. $excel\_path), and then image reference is normal (e.g. $image\_path).

I think there is a more elegant solution, but at the moment I cannot remember what it is.

It would look something like this:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/8/08f7ea218d7e45839e6b65019594142cc6921a47.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/d/7d462da89805a1b84056c0cc15c16d67aec13635.png)

This ^ would be two separate csv files. And make sure you set which loops are random or sequential properly. I think in my example I have those settings backwards (random within, sequential outer).

Best regards,

Issac

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [August 8, 2025, 8:45am UTC](https://discourse.psychopy.org/t/randomising-the-selection-of-different-series-while-keeping-items-within-each-series-sequential/45340/3 "2025-08-08T08:45:40Z")

</div>

This is the standard solution. The only refinement I would recommend is to use selected rows instead of different spreadsheets.

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/23):
>
> Avoid multiple spreadsheets One way of counterbalancing blocks in an experiment is to have an outer loop which points to a spreadsheet which contains the names of different spreadsheets to use in an inner loop. The main issue with this is that if you have multiple spreadsheets with the same columns and you want to make a change, you have to make it to all of them. The other more minor issue is that you may have to specify the spreadsheets as additional resources in Experiment Settings / Online. …

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [August 8, 2025, 9:19am UTC](https://discourse.psychopy.org/t/randomising-the-selection-of-different-series-while-keeping-items-within-each-series-sequential/45340/4 "2025-08-08T09:19:05Z")

</div>

Hello @reyams

I created a small toy-experiment that uses one condition-file.

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/e/ee83f59f9262a70cada984fcd8c734864d0ee9f6.jpeg)

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/0/b0a5fb9d8d3a65e382939e09cb52a30a2a76e557.png)

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/c/8c9d283a5fd4faa68b585a9bb6c398785283c237.png)

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/4/a49344ff4dcc01710ce7b9668a3fa037c20bf3dd.png)

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/0/c0d96b9f7423135536861a59ec244abef2348e62.png)

Begin Experiment tab

```auto
#randomise list order

listOrder = []
start = 0
while start < 51:
    ende = start + 3
    if ende > 51:
        break
    listOrder.append(f"{start}:{ende}")
    start += 3
    
#randomises list order
#turn off for testing
shuffle(listOrder)

useRows = []

```

Begin routine tab

```auto
#use to acces first element of listOrder
useRows = listOrder.pop(0)

#use to access last element of listOrder
#useRows = listOrder.pop()

```

The condition file has one column called ‘stimulus’, containing numbers from 0 to 49.

This example can easily be adapted to larger files, while still allowing one condition file to be used and maintained.

Best wishes Jens
