How to ensure randomised sound is 50/50 across trials

You still haven’t answered this. If the issue is how to balance the trials 50:50, then that requires that you take that constraint into account when generating this variable on a trial-by-trial basis. We don’t know how you have done that to date, so we can’t suggest improvements.

But starting from scratch, and without knowing anything else about your design (e.g. the number of trials), would suggest two approaches:

  • Set the sound volume variable from your conditions file, such that 50% of rows have a value of 0 and 50% a value of 1.
  • If for some reason that approach won’t work for you, then generate a balanced but randomised list of values and extract one value from the list on each trial:

Insert a code component. In its “Begin experiment” tab, put something like:

number_of_trials = 50 # use the real value

# create a balanced list of volumes:
sound_volumes = [0, 1] * (number_of_trials/2)

# randomise its order:
shuffle(sound_volumes)

Then in the “Begin routine” tab, select the next value:

current_volume = sound_volumes.pop()
thisExp.addData('volume', current_volume) # make sure to record it in the data

and then use current_volume to control the volume of your sound stimulus. Make sure the code component is above the sound component, so that the latter gets to refer to the latest version of the variable.