How to replicate the same random order of items from a list?

OS (e.g. Win10): Win10
PsychoPy version (e.g. v2022.2.4):
What are you trying to achieve?: I’m trying to create a random list of 15 items from a larger list of 48. I’m using the builder, but wrote code snippets. I’d like the random selection of items to be the same when I repeat the experiment! It’s for the combination of conditon files and I need my choice to be replicable.

What did you try to make it work?: Inside the loop I’m using
selected rows: $np.random.choice(48, size = 15, replace = False) to choose my 15 items from my list.
Setting random seed to anyting (1, 99, 0) didn’t do anything. I still got a different order of the 15 items each time I ran the experiment.
Also, setting random.seed() in the code to anything didn’t do it.

Here’s the code I’m using:
combination_list =
for i in range(1):
combination_list.append(combination)

shuffle(combination_list)

list_length = len(combination_list)

print(combination_list)

I’d be very grateful for any help :slight_smile: (Probably unnecessary to mention that I am quite the beginner with Psychopy…)

Kind regards
Lotti

If i understood your problem correctly, cant you set the ‘random’ order in the conditions file itself and then select sequential without any of the code components? afaik sequential is a simple and guaranteed way to get the same order of stimuli for every repeat of the experiment. im a beginner too so forgive me if i misunderstood.

You could also put a number in the “random seed” field of the loop

Hi Becca,

I tried that, but it didn’t work … I still get a different order everytime I run the experiment.

I think the issue is that you are using random twice in your loop.

Once for np.random.choice to select the rows and once for the random order.

Setting the seed should fix the order.

For the selected rows you need to set a variable to the random choice in a code component so it can be reused, instead of randomising each time.

Alternatively, use all rows and then break the loop early in a code component

if trials.thisN ==14:
     trials.finished = True