How to repeat tones randomly

Hi all,

My experiment involves two tasks in parallel. The primary task is to remember words and the secondary task is tone detection (press left or right arrow key according to different tones). Here’s the timeline.

My question is I don’t know how to achieve the tone stimulus. Each tone will be played for 1 s with a 0.75s interval and will be presented randomly from two pitches (400hz or 900hz) with the constraint that no pitch will be played more than three times consecutively. Can someone give me some suggestions? Thanks you so much!