How to pseudorandomise stimuli order

I am creating an auditory oddball task with two different tones (high pitch and low pitch) that represent green and orange bird song, respectively. There are four different conditions

  • 90% orange 10% green birds
  • 70% orange 30% green birds
  • 10% orange 90% green birds
  • 30% orange 70% green birds

This is the excel sheet I have created to represent those conditions:

Each block of my experiment will present 80 tones in either a volatile or stable condition (volatile is where the more prominent bird switched halfway through the trial). Therefore I will be using the loop feature with 8 repeats (for stable) and 4 repeats with a switch (for volatile).

I need to pseudorandomise the order that the tones are presented in so that within each repeat of the 10 tones, the deviant sound can never be followed by another deviant sound. As an extension to that, when the repeat begins again, the first and last sound can not both be deviant.

I’m not sure how to code for this (I’m assuming I will need to use the custom code component). One of my supervisors has said that making sure the repeat always starts on a ‘standard’ tone (the more prominent of the trial) will ensure that if the last repeat ended on a deviant tone, it won’t be followed by a deviant tone. But again I am not sure how to code for this!

Any help would be appreciated.

If you just need to be sure that the deviant sound never follows another, I would put in something to store which sound was played each trial, e.g. in the “End Routine” tab you could add:

lastTrialWasDeviant = isDeviant

(with isDeviant being either True or False depending on which trial was just played)

Then in the “Begin Routine” tab you could have:

if lastTrialWasDeviant:
    isDeviant = False
    isDeviant = ```Whatever your usual way of choosing deviant is```

Then the final thing would just be to have something in “Begin Experiment” defining lastTrialWasDeviant, so that when it gets to that if statement it isn’t looking for something which doesn’t exist. Here you can do what you supervisor suggested, make sure that it starts on a standard:

lastTrialWasDeviant = True

(so it will pretend the last trial was deviant, meaning the first will not be)