Randomize paired stimuli

Hi all,
I’m new to Psychopy and I don’t have much experience with python.

OS (e.g. Win10): Win11
PsychoPy version (e.g. 1.84.x): v2022.2.5
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:
I’m trying to present a prime phase followed by a probe phase in each trial. Whitin each phase I’ll present a compound stimulus consisted of a transparent Face and Word (Chinese character) superimposed on each other. Each of my stimulus has 2 versions (A and B), and I want to present version A in Prime phase and version B in Probe phase. I want to have 4 types of experiment trials (FrWr, FrWa, FaWr & FaWa; r for repeat, a for alter) and 2 response trials. For FrWr trials, I want both Face and Word Stimuli to repeat in Prime (e.g., FA1, WA1) and Probe phase (FB1, WB1). This one is simple I know Psychopy read the same row in my excel sheet. However, if I want to alter the stimulus in FrWa, FaWr or FaWa trials, I want it to randomly select a stimulus (e.g., FA2 & WA5) for Prime phase, and then, if the stimulus is to be repeat, then select the version B stimulus in the same code (e.g., FB2 & WB5) for Probe phase. If the stimulus is to be alter, then randomly select a version B stimulus with the code other than the one in Prime phase (e.g., FB4 & WB7).
For the response trials I don’t care about whether the stimulus repeat or not, it can just randomly selecting stimuli for the 2 phases but it should appear less frequently than the experiment trials.

What did you try to make it work?:
I filled the 4 types of stimuli in pairs in an excel sheet and it satisfies my need for FrWr trials in which both stimuli repeat. Since I want each stimuli to appear only once in a session, I’m not sure how to make Psychopy to select different rows of stimuli. (I was using e-Prime before and this can be done by using [PrimeFace: 0], [PrimeWord: 0], [ProbeFace: 1], [ProbeWord: 0]). So I’m thinking if I can define a random variable “n”, use it to pick the Prime stimulus with the last letter in the file name = “n”, and then for alter condition, use a random variable “m” which is not equal to “n” to select the Probe stimulus. Is there any better way to do this?

Thank you.