@Becca Thank you very much for the response. I think your approach would work well, although it is a somewhat messy (and time consuming) to create a different and separate conditions file per participant. I have have worked today in the same issue and I just out a way to do it quite nicely.
I defined a function in the “beginning of the experiment” tab of a code component that would take the name of excel file containing the trials as argument to load the trials in their original order, then randomize such trials based on some particular condition(s) and finally would return a list of the final order of such trials. Setting a loop in the builder to follow a “sequential order” rather than a “random order”, I called the function that I created in the “selected rows” space and the result is that psychoPy presents stimuli in the exact sequential order that my pseudo-randomization function returns.
Note that: For this approach to work, it is important to have a column in the conditions files that indexes the original sequential order of the stimuli so that once the stimuli list is correctly randomized the final order of the trials can be retrieved.
Here is the code that I used. To illustrate, I set the randomization condition to not allow two consecutive trials of the same stimuli type:
def pseudoRand(excelFile):
# Load trials
trials=data.importConditions(excelFile)
conditionMet = False
# Pseudo-randomize trials
while conditionMet == False:
random.shuffle(trials)
conditions = []
for row in range(len(trials)):
conditions.append(trials[row]["stimuliCondition"]) #Name of the conditions type column
# Condition for pseudo-randomization: No consecutive same type
for row in range(len(trials) - 1):
if trials[row]["stimuliCondition"] == trials[row + 1]["stimuliCondition"]:
conditionMet = False
break
else:
conditionMet = True
# Save the final order of the trials
customOrder = []
for row in range(len(trials)):
customOrder.append(trials[row]["originalIndex"]) #Name of the original index column
return customOrder