What are you trying to achieve?:
I’m trying to randomize two columns in my conditions file, one sound and one image, so that they do not always occur in the same pairs.
E.g. sound 1, 2, 3, 4 and image a, b, c, d not always occurring in the combinations 1-a, 2-b, 3-c, 4-d.
What did you try to make it work?:
I know this is a issue that has been brought up multiple times in the forum.
I have tried the 2012 solution offered here with the following code:
https://groups.google.com/g/psychopy-users/c/WljgXeoy6Ik
import random
import csv
first=[1,2,3,4]
second=[“A”,“B”,“C”,“D”]
firstRand=random.sample(first,len(first))
secondRand=random.sample(second,len(second))
with open(‘order_file.csv’,‘wb’) as w:
write=csv.writer(w)
writer.writerow([‘first’,‘second’])
for i in range(len(firstRand)):
writer.writerow([firstRand[i],secondRand[i]])
What specifically went wrong when you tried that?:
Not only does this solution not work for me (NameError: name ‘writer’ is not defined) but it’s also unclear to me how it is supposed to work.
I’m not using a csv file but an excel file as my conditions. Am I supposed to enter the names of my files in the first= and second= lists? I’m using over a 100 files so I’d like to avoid this.
I’m hoping there is a more recent solution to this problem, as I know it is a common one.