Have a look at my PM N-Back demo to see how I randomise an N-Back task. I preload the stimuli in random order and insert the repeats during the construction of the trial list.
I’m currently using similar code for a student who just wants N-Back with no Prospective Memory targets.