I have 6 blocks that contain 29 trials each. Block order is randomized (from a list of 6 rows in a file called block_order.xlsx) by a loop (works fine). The trial order for each block (block1.xlsx, etc.) is randomized (works fine). Each trial belongs to a category, indicated in a ‘category’ column. Every category has at least two trials in each block. The problem I have is that I want to constrain the randomization so that two consecutive trials must not be of the same category. I realize this requires custom code to implement. I have tried this and failed. I think I have two specific problems:
Most of the examples I have seen (example below) provide code that goes in “Begin Exp.” My problem is that I want this constraint applied within each block, not across the entire experiment. “Begin Exp.” does not seem to me to be the right place to put this code.
I assume that means that the code should run at the beginning of a routine that is at the beginning of my trial loop, and that it should run when thisN == 0.
I was able to change the example code above so that I could get the trialList for a block and loop through it to check for duplicate categories. What I have not been able to figure out is how to update trialList to a reshuffled order (e.g., the code in the example topic doesn’t update anything other than the array it made for demonstration purposes. I have tried setting trials.trialList to the reshuffled list, but it doesn’t work.
You can set use rows for a loop to a custom ordered list and set the loop type to sequential, but you would need to do this before the loop starts, so use concentric loops with the outer loop for the blocks.
There are some examples that might be helpful here:
Complex randomisation and randomisation without repetition show two different approaches.
Thanks. I have thought of that, but then the order of stimuli for each participant will be the same. I would ideally like the within-block trial order to be different–but within my constraints–for each participant.
I’m afraid I do not understand. I also looked at your code examples (including complex-randomisation.psyexp). The problem is that I do not really know Python well enough to follow what you’re doing. If this question has a simple answer, then maybe I can figure it out: is it possible in a routine at the start of a trial loop to shuffle and replace the trialList?
I have tried
currentTrialList = trials.trialList (then do a bunch of checking, which seems to work fine)
shuffle(currentTrialList)
trials.trialList = currentTrialList
This doesn’t work.
I really appreciate your taking the time to try to help, but I think I’m going to have to try a different tack. I am sure this is largely due to my lack of Python knowledge, which I do not have time to address before running this experiment.