If I am right, you have a list of path to all images. You also have a list with paths to all text files. An image path at index i corresponds to same index i in the list that contains paths to text files.
So generating a random number and using it as an index would solve the problem.
If you have already have 5 pairs of images and text files, then generating a random number and using it to access the image and path would solve it.
I may have not understood your problem correctly, but I answered what I could infer.