Skip to content

Constrained condition order

Shuffle trials while guaranteeing the same condition never runs more than twice in a row.

Use this when trial order is randomised but long streaks of one condition would let participants adapt, as in conflict tasks where a run of congruent trials relaxes control and inflates the following incongruent costs. A plain shuffle cannot help you here, because by chance alone it regularly produces runs of four or five same-condition trials. An ordering constraint keeps the randomness while capping the streaks. If your conditions carry no sequential risk, skip the spec and shuffle plainly; if you need strict alternation rather than a cap, that is a different spec on the same column.

typecontentstimFormatstim1condition1trialOrderkeyboardkeybutton1
instructionsPress H or S to match the CENTRE letter.NEXT
testwordHHHHHcongruent1: shuffle; maxRun 2 condition1h sh
testwordSSSSScongruent1h ss
testwordHHHHHcongruent1h sh
testwordSSHSSincongruent1h sh
testwordHHSHHincongruent1h ss
testwordSSHSSincongruent1h sh

A plain shuffle happily produces five incongruent trials in a row, which lets participants settle into a strategy. Here every flanker trial carries the run tag 1 in trialOrder, and one row’s cell spells out the program: 1: shuffle; maxRun 2 condition1. The shuffle word is what randomises the group, and the constraint narrows which shuffled orders are acceptable. Ordering specs do not drop any trials; after the shuffle, the group is reordered so that no more than 2 consecutive trials share a condition1 value. Write the spec on any one row of the group; the other rows take the bare tag 1.

The stimuli are letter strings shown with stimFormat word: participants respond to the centre letter, so key follows the centre letter while condition1 records whether the flankers agree with it. condition1 is also copied into every results row, ready for the congruency analysis.

The instructions row leaves trialOrder empty, so it keeps its position ahead of the shuffled block. If the constraint ever becomes unsatisfiable (say, far more incongruent than congruent trials), the session halts with an error page rather than running in a bad order; in preview mode the best order found is kept instead.

  • Forbid immediate repeats entirely: 1: shuffle; noRepeat condition1 in trialOrder stops two trials with the same condition1 value from ever being adjacent.
  • Force strict alternation: 1: shuffle; alternate condition1 in trialOrder makes the conditions take turns.
  • Control spacing of one condition: 1: shuffle; gap 1 3 condition1 in trialOrder demands 1 to 3 other trials between repeats of a value.
  • Fix the opening trial: add ; first condition1 congruent in trialOrder so the block always starts on a congruent trial.