Hey im trying to work out what method to use to order my image sequences

I have 2 images displayed on the screen at any one time and the user has respond or image time out after 240ms

the problem is i have 4 folders of images call them a,b,c and d folders
i have txt lists of all images in these directories ie picA.txt picB.txt picC.txt and picD.txt

the images themselves can never be the same image if drawn from the same imageset
the valid orders are of the two images displayed at any time are as below
A,A
B,B
C,C
D,D
A,C or C,A
A,B or B,A
A,D or D,A
C,B or B,C

what method to organise these groups would work best?
as i said above i have image lists for each of the 4 folders at the moment and i can display the images and make sure there only displayed once each and never repeated. im just not sure how to randomly pick between entire different groups of stimuli
thanks for any help
richard