We have an experiment where we want to randomly present an item from one of three separate lists from an Excel spreadsheet. We need one method of randomization that will select a column and another that will select an item within that column. Each list has more than 30 items but we only want to show 30 items from each list (90 items overall). Is there a code we can use that will repetitively randomly select a column and then an item only 30 times from each column until all 90 items have been shown?
Instead of a spreadsheet, I’de suggest instead having 3 lists with your values in them and then randomly sampling on each trial. So, add a code component:
Begin Experiment Tab:
# set up your values in lists
list1 = [val1, val2, val3]
list2 = [val4, val5, val6]
list3 = [val7, val8, val9]
# list those lists
all_lists = [list1, list2, list3]
# create a list of indices (that are randomised
list_choices = [0]*30 + [1]*30 + [2]*30
shuffle(list_choices)
Begin Routine tab:
thisvalue = all_lists[trials.thisN][-1]
# remove this value so it is not sampled again
all_lists[trials.thisN].pop()
In your actual trial, set the loop name around your trial routine to be “trials” (which allows trials.thisN to work) and nReps to be 90.
If you already have your spreadsheets set up, and don’t want to faff putting these in lists. Use this script (in PsychoPy coder) to generate the lists that can just be copied and pasted into your code component.