Random attentional check in a loop of auditory tone sequence

Hi all,

I’m programming an experiment in PsychoPy with a simple structure, but I’m having difficulty with inserting random attentional checks. I have a loop called “trial”, repeated 52 times, contains two internal loops. The first loop, which is not relevant to my current issue, presents different auditory stimuli. The second loop, called “imagery”, presents a single tone (one routine) repeated 12 times.

I want to add 5 attentional checks (at maximum one for each trial) within the “imagery” loop. These checks would involve replacing one of the repeated tones (the repeated routine) with a different tone in the imagery loop (and when this different tone plays, a response screen should appear). At the end I aim to have 5/52 trial that contains this changed tone.

Do you have any ideas of what can I do, specifically where I should insert the code component, where insert the routine “attentional check” or any other changing in the task structure, that - combined with a code - can help me structuring the task?

Thank you for your time!